2

Closed

HtmlHelper.TextBox does not understand value parameter

description

Textbox maintains ModelState value and does not get replaced with parameter.

If I were to utilise the following
<%=Html.TextBox("Message", (ViewData["Message"]))%>
the ViewData would get ignored on Post. Use of reflector and regenerating extension methods show that the ViewData would get ignored and the value would be onbtained from ModelState.

Unfortunately to get it working I had to do the following

ModelState.SetModelValue("Message", new ValueProviderResult(Message, Message, System.Globalization.CultureInfo.CurrentCulture));

which is potentially buggy and messes up state.
Closed Mar 17, 2009 at 6:35 PM by
By design (see comments).

comments

auriel wrote Mar 17, 2009 at 6:16 AM

This behavior is intentional. ModelState is always queried first so that the user's input is not blown away if the form has to be redisplayed. The 'value' parameter is used as a fallback if ModelState has not been populated.