Is it standard/intended behaviour that the value of a hidden form field is not bound to the view model (nor is a query string value)?
Example:
<%= Html.Hidden("test", "13" )%>
if my poco view model contains a property test it should be bound shouldn't it?! i have to set it explicitely in the controller at the moment which kind of defeats the objective doesn't it?
bla( formviewmodel m, string test)
{
m.test = test;
}
any feedback appreciated. thanks!
christian
Edit:
I inspected the form values like this:
string[] t = Request.Form.AllKeys;
for( int 开发者_JAVA技巧c = 0; c < Request.Form.AllKeys.Count(); c++ )
{
string[] x = Request.Form.GetValues(c);
}
and it definatley contains the value of test.
The value for the hidden field is taken from Modelstate.
That can be from the URL (Roting value) or from a post.
The second paramter for the helper is only the default if no data exists from route or post.
You probably want to use
<input type="hidden" value="<%=Model.Test%>" name="Test" >
I did not see a view where the Html.Hidden field makes sense yet.
精彩评论