controller post action not able catch list of objects

后端 未结 1 1389
广开言路
广开言路 2021-01-28 01:32

It may duplicate question, i have searched all over but couldn\'t satisfied, so i am posting here question.

I have object as (generated from entity framework),

相关标签:
1条回答
  • 2021-01-28 02:18

    You cannot use .ElementAt(). If you inspect the html your generating you will see that the name attribute has no relationship to your model.

    You model needs to implemet IList<Usp_Sel_NotEnteredStringResources_Result> and use a for loop

    @for (int i = 0; i < Model.Count; i++)
    {
        <tr>
            <td>@Html.DisplayFor(m => m[i].name)</td>
            <td>
                @Html.TextBoxFor(m => m.[i]Value)
                // note you hidden inputs should be inside a td element
                @Html.HiddenFor(m => m[i].LanguageId)
                ....
            </td>             
        </tr>
    }
    

    Alternative if the model is IEnumerable<Usp_Sel_NotEnteredStringResources_Result>, you can use an EditorTemplate (refer [Post an HTML Table to ADO.NET DataTable for more details on how the name attributes must match your model property names, and the use of an EditorTemplate)

    0 讨论(0)
提交回复
热议问题