I have seen the client side validation examples and videos on internet by using Html.EnableClientValidation(). But all target on the simple data model.
Does the Html.EnableClientValidation() work on the nested data model like below?
public class Person
{
public Name Name { get; set; }
public string Gender { get; set; }
}
pub开发者_如何学JAVAlic class Name
{
public string First { get; set; }
public string Last { get; set; }
}
Yes it will work. You just have to set data annotation attributes on your required class members.
[Required(ErrorMessage = "first name is required")]
public string First { get; set; }
Note that you only have to set data annotation on only First
member of Name
. There is no need to set data annotation on Person
member Name
精彩评论