i have a applied dataanootation validation attribu开发者_开发技巧te to my class for the create view
[Required(ErrorMessage = "Password is required")]
public string vcr_Password { get; set; }
What could be the best way in which i can made it not mandatory for edit in asp.net mvc3 ?(note i cannot remove the validationmessage for it)
Since your validation rules are different for create and edit. I would suggest creating two different models. One that handles create and one that handles edit.
public class CreateFoo
{
[Required(ErrorMessage = "Password is required")]
public string vcr_Password { get; set; }
//other properties.
}
public class EditFoo
{
[Required]
public int Id {get;set;}
//other properties that might be editable..
}
精彩评论