Foreach on IEnumerable property and CheckBoxFor in ASP.Net MVC

后端 未结 2 1853
面向向阳花
面向向阳花 2020-12-30 07:48

I believe this question applies to any of the \"For\" Html helpers, but my specific problem is using CheckBoxFor...

I have a model that is of type IEnumerable, where

2条回答
  •  灰色年华
    2020-12-30 08:28

    I found the answer by using a blog post by Steve Sanderson at http://blog.stevensanderson.com/2010/01/28/editing-a-variable-length-list-aspnet-mvc-2-style/

    Using "Html.BeginCollectionItem" worked in my situation.

    I created an EditorTemplate for rights (in my example). Then added Steve's BeginCollectionItem to that template. I called the template using Html.RenderPartial as suggested in Steve's blog.

    I wanted to use Html.EditorFor(m => m.item), but that doesn't work because item is in the ForEach and not in the model. Could EditorFor be used in this case?

提交回复
热议问题