I’m using asp.net mvc 3 for a project and already using the server and client validation on several pages. It works fine. But this time, I’ve a special case:
Items in the view are bounds to the model and also to some of its properties.
one example:
public class MyModelView{
[Required]
[StringLength(100, MinimumLength = 2)]
public String Name{get;set;}
public DetailsObject Details{get;set;}
}
public class DetailsObject{
[Required]
[StringLength(100, MinimumLength = 2)]
public String PropertyOne{get;set;}
[Required]
[StringLength(100, MinimumLength = 2)]
public String PropertyTwo{get;set;}
}
and in the view I’ve “bindings on all elements
@Html.TextBoxFor(m=>m.Name)
@Html.TextBoxFor(m=>m.Details.PropertyOne)
@Html.TextBoxFor(m=>m.Details.PropertyTwo)
The problem is that I don’t get any client validations. The server validation is still working fine for all properties.
I’ve the jquery validate unobtrusive included. How do you manage that?
there are several places you should check
web.config should have those lines
check the javascripts to be included in right order
also as a reminder (as I don’t see the whole view file) place
ValidationMessageForhelpers to see validation errors