开发者

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

开发者 https://www.devze.com 2022-12-27 17:33 出处:网络
I have seen the client side validation examples and videos on internet by using Html.EnableClientValidation(). But all target on the simple data model.

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

0

精彩评论

暂无评论...
验证码 换一张
取 消