# How to clear ModelState errors on server-side?

**URL:** <https://forum.dotvvm.com/t/how-to-clear-modelstate-errors-on-server-side/339>\
**Category:** Discussion in English\
**Created:** [July 31, 2025, 9:46am UTC](https://forum.dotvvm.com/t/how-to-clear-modelstate-errors-on-server-side/339 "2025-07-31T09:46:31Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![MarianV](https://forum.dotvvm.com/letter_avatar_proxy/v4/letter/m/c0e974/32.png) [@MarianV](https://forum.dotvvm.com/u/MarianV)\
**Post date:** [July 31, 2025, 9:46am UTC](https://forum.dotvvm.com/t/how-to-clear-modelstate-errors-on-server-side/339/1 "2025-07-31T09:46:31Z")

</div>

Hi there,

On a popup (`ModalDialog`) I’m currently working, we use `Context.AddRawModelError()` to do some server-side custom validations.

I trigger one of those errors, a message is shown in red on the page.  
I close and reopen the popup (the VM of the popup is reinstantiated) but the error is still there.

I know about clearing errors on the client-side ([https://www.dotvvm.com/docs/4.0/pages/concepts/validation/extensibility](https://www.dotvvm.com/docs/4.0/pages/concepts/validation/extensibility))  
but how do I clear them up in the server-side code?  
`Context.ModelState.Errors` shows me 0 errors while the error message still shows in the page.  
I could not find anything of help in the members of Context or among its extension methods. Looking a bit deeper at `AddRawModelError()` and in the framework’s code, following `ModelState.ErrorsInternal`, I did not find any means of removing errors from the state by the framework consumer.

So, am I stuck with the client-side clearing of the errors?

---

<div class="post-metadata">

**Author:** ![exyi](https://forum.dotvvm.com/user_avatar/forum.dotvvm.com/exyi/32/9_2.png) [@exyi](https://forum.dotvvm.com/u/exyi)\
**Post date:** [August 6, 2025, 1:20pm UTC](https://forum.dotvvm.com/t/how-to-clear-modelstate-errors-on-server-side/339/2 "2025-08-06T13:20:00Z")

</div>

This is quite strange, as client-side error should be cleared on each command invocation (if validation is enabled). How exactly are you calling the server? It is also theoretically possible that the error are added back to ModelState after you clear them - Init/Load methods execute before the server-side validation is run.

---

<div class="post-metadata">

**Author:** ![MarianV](https://forum.dotvvm.com/letter_avatar_proxy/v4/letter/m/c0e974/32.png) [@MarianV](https://forum.dotvvm.com/u/MarianV)\
**Post date:** [September 20, 2025, 7:31am UTC](https://forum.dotvvm.com/t/how-to-clear-modelstate-errors-on-server-side/339/3 "2025-09-20T07:31:51Z")

</div>

For the particular DotVVM page in question where we have this issue, the `Context.AddRawModelError()` is called **only** inside our `DoServerValidationBeforeAnyOperationPersistence()` method. This one is called in two places:

1. in `public async Task PreSaveOperationAsync()` which is top level method, only used in binding here:  

2. in `public void OnClick_SaveOperation()` which also is top level and used only here:  

**PS**  
How the markup of the outermost ModalDialog starts:  
 ![image](https://forum.dotvvm.com/uploads/default/optimized/1X/42a51cb03854fa955fbb5b99bc4236a2d3665bc9_2_690x48.png)

I do not know if the disabled validation or that Render mode have anything to do with the issue. I just find them outside of the ordinary.

---

<div class="post-metadata">

**Author:** ![exyi](https://forum.dotvvm.com/user_avatar/forum.dotvvm.com/exyi/32/9_2.png) [@exyi](https://forum.dotvvm.com/u/exyi)\
**Post date:** [September 20, 2025, 9:27pm UTC](https://forum.dotvvm.com/t/how-to-clear-modelstate-errors-on-server-side/339/4 "2025-09-20T21:27:29Z")

</div>

Yes, disabled validation means that Dotvvm won’t clear the client-side error collection on postback. I think you should be able to set Validation.Target to `{value: null}` to disable automatic validation and only keep the manual one
