client side asp.net mvc validation for non "For" fields
So i have the following checkbox (tho my question relates to any type of field )
Within the same form i have
Model.UserProfile)%>and this validation is working fine from the following js files
<script src="/Scripts/jquery-1.3.2.min.js" type="text/javascript"></script>
<script src="/Scripts/MicrosoftAjax.js" type="text/javascript"></script>
my question, i wish to validate fields that are not part of the "EditorFor".
I could bind the click event with the following js file
However i'm wondering is this the best way to do it, or am i missing tric开发者_开发百科k. Do i realy need to do this via "/Scripts/jquery.validate.min.js"
The validators are normally generated from the Data Annotations. If you want to do client validation, you might want to wrap those object into another object.
The standard practice recommend that you use a "ViewModel" to generate a model that match your view but not necessarily the business model. This allows you to use Data Annotation for those objects (and generate validation) and use different rules for your business model.
Does that answer your question?
精彩评论