MVC binding to model with list property ignores other properties

后端 未结 3 891
别跟我提以往
别跟我提以往 2020-12-08 07:20

I have a basic ViewModel with a property that is a List of complex types. When binding, I seem to be stuck with getting either the list of values, OR the other model propert

3条回答
  •  一整个雨季
    2020-12-08 07:39

    Try to change the code for the Data collection to this, and let MVC take care of the naming:

    @for (int i = 0; i < Model.Data.Count(); i++) { @Html.HiddenFor(m => m.Data[i].Id) @Html.HiddenFor(m => m.Data[i].ParentId) @Html.HiddenFor(m => m.Data[i].Name) @Html.TextBoxFor(m => m.Data[i].Value) }

提交回复
热议问题