ASP.NET MVC2. Does Html.EnableClientValidation () work on a nested data model?

I have seen client-side validation examples and videos online using Html.EnableClientValidation (). But all goals are in a simple data model.

Does Html.EnableClientValidation () work on a 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; }  
}  
+3
source share
1 answer

Yes it will work. You just need to set data annotation attributes for your required class members.

[Required(ErrorMessage = "first name is required")]
public string First { get; set; }

Note that you only need to set the data annotation for the member only First Name. No need to set data annotation on PersonmemberName

+2
source

Source: https://habr.com/ru/post/1742399/


All Articles