How to set ModelState true from controller action

How to set ModelState = true; in asp.net MVC from controller action
, since we know ModelState.IsValid we only read that is. only has a getter, so we cannot get our modelState to be true, like this
ModelState.Isvalid = true; //what we can't do

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

+4
source share
1 answer

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

+14
source

Source: https://habr.com/ru/post/1394370/


All Articles