开发者

Ignoring [Required] data annotation

Why is MVC still valida开发者_如何转开发ting this property as I already excluded it?

...
[Required(ErrorMessage = "Please enter activation code")]
public string ActivationCode { get; set; }
...

[HttpPost]
public ViewResult CreateAccount([Bind(Exclude = "ActivationCode ")] AccountCreationViewModel m, string returnUrl)
...


You are excluding the ActivationCode here from being able to be bound to your view model.

However the ModelBinding will still validate the complete model.

I would suggest creating a new ViewModel for your purpose, or a filter as suggested by Steve Sanderson here


Not sure if it does exactly the same as what you have but I have done something like this and it has worked.

[ValidateInput(true, Exclude="ActivationCode")]
[HttpPost]
public ViewResult CreateAccount(AccountCreationViewModel m, string returnUrl)
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜