ASP.NET MVC 4 - EditorTemplate for nested collections

风流意气都作罢 提交于 2019-12-06 09:11:35

Don't use the foreach. EditorTemplates already iterate over collections if you pass it a collection.

@model MyNamespace.ExerciseForPupil

@using (Html.BeginForm("ScoreExercise", "SharedLesson"))
{
    @Html.HiddenFor(x => x.Id)
    @Html.EditorFor(x =>  x.ExerciseItemsForPupil)
    <input type="submit" value="Submit"/>
}

A few things to note. You don't have to pass the template name, as the template name is already the same name as the item type. You don't have to use the Post formmethod, as that's the default. There is no name of the property for List so I just assumed it was the plural.

Your last class is also illegal, you would not specify it as a List like that.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!