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)
精彩评论