模型绑定复选框问题列表 [英] Model binding a list of checkboxes problem

查看:68
本文介绍了模型绑定复选框问题列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的EditorTemplates中,我有两个视图.一种用于我的类别(称为_Category)

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 />

和一个类别列表(称为_Categories)

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?

预先感谢

推荐答案

请参考用于集合数据绑定,那是为此的两个最终资源.

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

这篇关于模型绑定复选框问题列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆