Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Html.Hidden() inserting wrong value

When I use a form html helper method in one of my views like <%=Html.Hidden("id", "some id text") %> it creates a hidden input field for me but it puts the wrong value in there.

Instead of getting

<input name="id" type="hidden" value="some id text"/>

I get

<input name="id" type="hidden" value="11000"/>

So the value is being found from somewhere else. In this case it's the primary id of the parent record. So it is an id, it's just the wrong id.

Does anyone have any ideas? I'm pretty sure this didn't happen in MVC1

like image 962
Jero Avatar asked Nov 15 '22 08:11

Jero


1 Answers

Model binding always takes precedence. The model binder doesn't know of if a field is hidden. See http://forums.asp.net/t/1559541.aspx and http://forums.asp.net/t/1703334.aspx

like image 66
RickAndMSFT Avatar answered Dec 29 '22 10:12

RickAndMSFT