Model binding a list of checkboxes problem

折月煮酒 提交于 2019-12-07 04:49:46

问题


In my EditorTemplates, i Have two Views. One for my Category (called _Category)

@model com.example.Models._Category
@Html.CheckBox(Model.Name, Model.Selected)
@Html.LabelFor(c => c.Name, Model.Name)
<br />

and one for the List of Categories (called _Categories)

@model List<com.example.Models._Category>
@for (int i = 0; i < Model.Count; i++)
{
    @Html.EditorFor(c => Model[i]);
}

In the view that shows these categories, i have a list of Categories which is being used like so:

@Html.EditorFor(m => m.Categories, "_Categories")

When I view the page, there are multiple checboxes with names next to them which is good. The name of the checkboxes is not so good however as they turn out to look like this:

....name="Categories.[1].Batman"....">

There is an extra dot in the name which needs to go away. Any ideas on how to fix this?

Thanks in advance


回答1:


Please refer to this and this for collections databinding, those are two ultimate resources for that.




回答2:


I saw this post that I believe talks about the same issue that you are having. Might be helpful.



来源:https://stackoverflow.com/questions/7114602/model-binding-a-list-of-checkboxes-problem

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