tags:

views:

44

answers:

1

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 c = 0; c < Request.Form.AllKeys.Count(); c++ )
        {
            string[] x = Request.Form.GetValues(c);
        }

and it definatley contains the value of test.

A: 

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.

Malcolm Frexner
I am sorry I must be missing something. When I use: <%= Html.Hidden("Test", Model.Test)%> it produces this: <input id="Test" name="Test" value="7007" type="hidden">. This should be fine but it is not - Test is not bound! Test is posted (see firebug but NOT bound)
csetzkorn