Why input elements don't render the value passed in ASP.Net MVC?

Posted by MediaSlayer on Stack Overflow See other posts from Stack Overflow or by MediaSlayer
Published on 2010-03-19T14:49:40Z Indexed on 2010/03/19 14:51 UTC
Read the original article Hit count: 179

Filed under:
|

This post asks this question but doesn't really give an answer, so I thought I would ask the question differently.

I have a page that renders a hidden value from the model:

<%=Html.Hidden("myName", model.myValue) %>

Since I am passing a value in the value parameter, you would think it would output that value, but it doesn't.

The code for rendering input fields has the following:

string attemptedValue = (string)htmlHelper.GetModelStateValue(name, typeof(string));
tagBuilder.MergeAttribute("value", attemptedValue ?? ((useViewData) ? htmlHelper.EvalString(name) : valueParameter), isExplicitValue);

Basically, if the ModelState (which contains posted values) contains a value for the "name" passed, it will use that value instead of your passed value to the helper method. In my case, I updated the model and my updated value wasn't outputted.

If I pass a value to a method, I expect that value to be rendered.

Am I missing something in this design or is it just wrong?

© Stack Overflow or respective owner

Related posts about asp.net-mvc2

Related posts about asp.net-mvc