Here's the Controller logic block that deals with that: The logic is straight forward - if the new email address is not valid because it already exists I don't want to display the new email address the user entered, but rather the old one.To do this I change the value on the model which effectively does this: So when I press the Save button after entering in my new email address ([email protected]) here's what comes back in the rendered view: Notice that the textbox value and the raw displayed model value are different.You do want to get the POST values back into your input controls at all times, so that the data displayed on a form for the user matches what they typed.So if an error occurs, the error doesn't mysteriously disappear getting replaced either with a default value or some value that you changed on the model on your own. Still it is a little non-obvious because the way you create the UI elements with MVC, it certainly looks like your are binding to the model value: and so unless one understands a little bit about how the model binder works this is easy to trip up. Even though I'm telling the control which model value to bind to, that model value is only used initially on GET operations.In this article we will learn how to maintain the state of dynamically created controls in using c#.Retain the state of dynamic created controls or maintain the data of dynamic created/ added user control on postback in
Effectively it looks like you can't change the display value of a control via model value updates on a Postback operation. I have a small section in a document where I display an editable email address: This is what the form displays on a GET operation and as expected I get the email value displayed in both the textbox and plain value display below, which reflects the value in the mode.
The Text Box displays the POST value, the raw value displays the actual model value which are different.
This means that MVC renders the textbox value from the POST data rather than from the view data when an Http POST is active.
These are much shorter posts than some of the more involved ones that I do, but cover common questions and tips that I get via email. NET you would simply edit the "Script Manager" object within your aspx page and set the control in question to be a Post Back Control.
A very common request that I get from developers after they have set the "Supports Partial Rendering" flag within their module manifest is how can they set a control to force a postback quickly & easily. You need to do this if you are modifying the request headers or other advanced operations such as forcing a full page update.