views:

519

answers:

1

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; }  
}  

public class Name
{  
    public string First { get; set; }  
    public string Last { get; set; }  
}  
+2  A: 

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

Adeel