我正在开发一个ASP.Net MVC 3 Web应用程序,我最近发表了一篇关于如何显示的CheckBoxListASP.Net MVC 3个多CheckBoxLists
ASP.Net MVC 3 Retrieve Checkbox List Values
,并感谢来自RubbleFord和帮助问题达林季米特洛夫我能够得到这个工作。
这适用于一个checkboxlist,但是,现在我需要能够在同一个视图上显示多个checkbox列表,即查看附加的图片。是
我使用当前显示一个列表中的的ViewModels如下;像
public class ViewModelShiftSubSpecialties
{
public ListItem specialtyName { get; set; }
public IEnumerable<ViewModelCheckBox> SubSpecialityList { get; set; }
}
public class ViewModelCheckBox
{
public string Id { get; set; }
public string Name { get; set; }
public bool Checked { get; set; }
}
我的控制器中我填充ViewModelShiftSubSpecialties这样:
var subSpecialties = GetSubSpecialtiesForSpecialty(5);
ViewModelShiftSubSpecialties viewModel = new ViewModelShiftSubSpecialties();
var checkBoxList = new List<ViewModelCheckBox>();
viewModel.specialtyName = _listService.GetListItemByID(5); //Medicine Specialty
foreach (var item in subSpecialties)
{
ViewModelCheckBox chkBox = new ViewModelCheckBox { Id = item.subID.ToString(), Name = item.ListSub.description, Checked = false };
checkBoxList.Add(chkBox);
}
viewModel.SubSpecialityList = checkBoxList;
在我看来,我显示列表名称,并使用编辑器模板来显示的CheckBoxList
<h3>@Model.specialtyName.description</h3>
@Html.EditorFor(m => m.SubSpecialityList)
然而,我完全难以理解如何让上面的代码与一个View上的多个复选框列表一起工作。这甚至有可能吗?
我真的很感激,如果有人可以请帮我这个。
谢谢。
这看起来不错,谢谢。你能否详述一下你的第二个解决方案?谢谢。 – tgriffiths 2012-04-17 15:15:27
感谢这个AFinkelstein - 这真的很有用。 – tgriffiths 2012-04-17 15:27:52
当然,很乐意提供帮助。 – DMulligan 2012-04-17 15:33:01