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 i开发者_开发知识库n MVC1
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
I can thing about following options
- Value you are passing to the view is wrong, eg. data passed to view(you can check debugging in controller to see what are you passing into it
- You are using ViewData and TempData data with different values which are overridden
else please put here your code so we all can see what is wrong
精彩评论