RequiredIfNot Client-side validation

Jun 14, 2012 at 10:11 AM
Edited Jun 14, 2012 at 10:13 AM


I'm trying to use the RequiredIfNot attribute. The server-side validation works well, but client-side validation won't works.
I'm using it in an MVC 3 Razor project, using unobtrusive validation.
I've included the following js:

    <script src="@Url.Content("~/Scripts/jquery-1.7.1.min.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/jquery.layout.min.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/jquery-ui-1.8.18.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/jquery.unobtrusive-ajax.min.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/mvcfoolproof.unobtrusive.js")" type="text/javascript"></script>

and those are my properties:

[Display(Name = "Km percorsi")]
public decimal KmPercorsi { get; set; }

[Display(Name = "Partenza")]
[RequiredIfNot("KmPercorsi", 0, ErrorMessage = "Il campo è obbligatorio se si inseriscono i km.")]
public string LuogoPartenza { get; set; }


Any idea?

Jun 18, 2012 at 12:35 PM

Same here. I can't get client validation to work in obtrusive. 

Can't see what's wrong while debugging, I see the data attributes in the html and the foolproof adapters being added to  $.validator.unobtrusive.adapters. 

The built-in attributes work just fine.