I'm trying to use the JQuery Validation's "addClassRules" method in my ASP.NET MVC application.
In my master page I'm including the following files...
<script src="<%= Url.Content("~/Scripts/MicrosoftAjax.js") %>" type="text/javascript"></script>
<script src="<%= Url.Content("~/Scripts/MicrosoftMVCAjax.js") %>" type="text/javascript"></script>
<script src="<%= Url.Content("~/Scripts/MicrosoftMVCValidation.js") %>" type="text/javascript"></script>
<script src="<%= Url.Content("~/Scripts/jquery-1.4.1.js") %>" type="text/javascript"></script>
<script src="<%= Url.Content("~/Scripts/jquery-validate.js") %>" type="text/javascript"></script>
I'm not sure which are actually required so I've added them all:) Potential problem area?
In my View I've got a simple textbox element which I'm trying to add the "required" validation via the Class attribute. I've got dynamic forms and my end goal is to specify different validation rules in the Class attribute. So for now I'm got something like this...
<%: Html.TextBoxFor(model => model.FieldEntry.Response.TextBoxValue, new { @class = "cRequired" } )%>
then at the end of my View I'm including the following script which I though was suppose to hook up the Class name to a validation rule.
<script language="javascript" type="text/javascript">
jQuery(document).ready( function()
{
jQuery.validator.addClassRules({
cRequired: {
required: true
}
});
})
</script>
Seems like a straightforward example but the problem I am having is that I keep getting an error that jQuery.validator is null or not an object. This refers to the first line of the the ready() function in the script above.
Any help / suggestions?