Ashish Sharma
Ashish Sharma

Reputation: 875

about asp.net MVC Validation

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 Applicant{

 [Required]
 propert1{get,set;}
 [Required]
 propert2{get,set;}
 [Required]
 propert3{get,set;}
 [Required]
 propert4{get,set;}

} 

Upvotes: 1

Views: 51

Answers (1)

Darin Dimitrov
Darin Dimitrov

Reputation: 1039368

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.

Upvotes: 1

Related Questions