I have a class that implements IValidateObject. My business rule is executed after completing additional work in the controller action. The problem I have is ModelState.IsValid, still false. I am trying to find how to reset this or retry to update ModelState. I tried TryUpdateModel, which ran the Validate method, and if I go through my rule it will now be valid, but ModelState.IsValid is still false (and I see that it still complains about the same rule).
[HttpPost] public ActionResult Create(MyModel model) { //ModelState.IsValid is False at this point //model.Do More Stuff To Satisfy IValidateObject rule. At this point all my rules are valid TryUpdateModel(model); // <-- If run TryUpdateModel and step through, I can see my rule is valid if (ModelState.IsValid) // this is still False { //Save } }
Update:
I ended up calling
ModelState.Clear();
[HttpPost]
public ActionResult Create(MyModel model) {
source share