I have a situation where I want to keep a hidden value between a POST controller. The hidden value changes when other values change. I could not get the hidden element to update without manually updating the value in ModelState.
I did not like this approach, since it was strange not to use a strongly typed reference to the model value.
I found that calling ModelState.Clear just before returning the View result worked for me. It seemed that then she would select the value from the Model, and not the values that were presented in the previous POST.
I think that there will probably be a problem with this approach for situations where you use errors in ModelState, but my script does not use model errors.
source share