Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 687
RollerCosta Avatar asked Feb 02 '12 10:02

RollerCosta


1 Answers

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.

like image 114
Darin Dimitrov Avatar answered Nov 15 '22 08:11

Darin Dimitrov