Why mvc Html.HiddenFor does not render my field?

后端 未结 4 898
甜味超标
甜味超标 2020-12-15 07:08

I\'m trying to do this simple thing

<%= Html.HiddenFor(model => model.Id)%>

the model is

[HiddenInput(DisplayValu         


        
4条回答
  •  眼角桃花
    2020-12-15 07:33

    I ran into this problem as well with @Html.HiddenFor.

    @Html.Hidden("Id", Model.Id) also gave value 0, but a foreign key field, e.g., @Html.Hidden("Model_Category_ModelId", Model.Category.ModelId) did work, while it @Html.HiddenFor(m => m.Category.ModelId) did not.

    My solution was to redirect to the get action, as described in ASP NET MVC Post Redirect Get Pattern.

提交回复
热议问题