开发者

asp.net mvc 3 dataannotation different edit scenario

开发者 https://www.devze.com 2023-02-15 22:06 出处:网络
i have a applied dataanootation validation attribu开发者_开发技巧te to my class for the create view

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..    
}
0

精彩评论

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

关注公众号