RollerCosta
RollerCosta

Reputation: 5186

How to set ModelState true from controller action

How to set ModelState = true; in asp.net MVC from controller action
as we know ModelState.IsValid is readOnly ie. holds getter only, So we can't force our modelState to true like this
ModelState.Isvalid = true; //what we can't do

Now do tell me guys what is the correct way to set modelsatate.isvalid to true

Upvotes: 7

Views: 8572

Answers (1)

Darin Dimitrov
Darin Dimitrov

Reputation: 1038850

You could ModelState.Clear() it. But this will remove all errors and values. If you want to remove only the errors you could loop through all elements in the ModelState and for each element remove the errors that might be associated to it. Once you do that, ModelState.IsValid will become true.

Upvotes: 20

Related Questions