i am using asp.net mvc 2 here i have a following class Applicant and it has its properties which are mentioned [Required] so if i add a new view in project of strongly type with Applicant Class and use only one property from applicant class Html.TextBoxFor(Model => Model.Property1) and when i use Model.IsValid it return False because i have not used supplied value for other required properties (property2,property3,property4). So is there any way for using same Applicant Class For different view and also validate only those Properties which i have used in view not those which have not used in view.
class Applic开发者_C百科ant{
[Required]
propert1{get,set;}
[Required]
propert2{get,set;}
[Required]
propert3{get,set;}
[Required]
propert4{get,set;}
}
So is there any way for using same Applicant Class For different view and also validate only those Properties which i have used in view not those which have not used in view.
I would recommend you creating view models for each view and having validation properties adapted to the needs of each view.
精彩评论