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 thisModelState.Isvalid = true; //what we can't do
Now do tell me guys what is the correct way to set modelsatate.isvalid to true
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
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With