@Html.HiddenFor does not work on Lists in ASP.NET MVC

后端 未结 13 963
灰色年华
灰色年华 2020-11-27 15:13

I\'m using a model that contains a List as a property. I\'m populating this list with items i grab from SQL Server. I want the List to be hidden in the view and passed to th

13条回答
  •  青春惊慌失措
    2020-11-27 15:34

    It's a bit of a hack, but if @Html.EditorFor or @Html.DisplayFor work for your list, if you want to make sure it's sent on the post request but not visible, you could just style it to using display: none; to hide it instead, e.g:

    @Html.EditorFor(model => model.MyList)

提交回复
热议问题