Important Notice: Our web hosting provider recently started charging us for additional visits, which was unexpected. In response, we're seeking donations. Depending on the situation, we may explore different monetization options for our Community and Expert Contributors. It's crucial to provide more returns for their expertise and offer more Expert Validated Answers or AI Validated Answers. Learn more about our hosting issue here.

Im setting the value of a hidden with tempData, but the value is always overridden on postback. Whats the problem?

0
0 Posted

Im setting the value of a hidden with tempData, but the value is always overridden on postback. Whats the problem?

0
0

On postback, all input helpers — including hidden — render the value that’s in ModelState rather than the value that’s provided from ViewData or the helper method. The assumption is that if you’re re-rendering the form on postback, then it’s because there was an error, and we should show the values the user typed rather than the values in the object. See http://forums.asp.net/p/1476843/3460584.aspx In your controller action, you could remove the hidden value from ModelState to force it to use the new value.

Related Questions

What is your question?

*Sadly, we had to bring back ads too. Hopefully more targeted.

Experts123