关于来自MVC3的editorFor helper我有一个奇怪的问题.事情是这样的:我正在尝试显示一个checkBoxList,如果我不调用明确的模板名称,它就可以工作.但是,如果我尝试使用模板名称,它会抛出一个异常,说我正在尝试传递一个通用列表,而我应该简单地传递我的viewmodel.我将展示一些代码以使其更易理解:
视图模型
public class Chkviewmodel { public string ContractName {get;set;} public string Contract {get;set;} public bool Checked {get;set;} }
EditorFor Template(称为ContractTemplate)
@model Models.Chkviewmodel <p> @Html.HiddenFor(x => x.Contract ) @Html.LabelFor(x => x.ContractName,Model.ContractName ) @Html.CheckBoxFor(x => x.Checked,new { @class = "chkContract" }) </p>
摘自我的观点
<div id="contractContainer"> @Html.EditorFor(item=>item.ContractList) </div>
这很好用.但它试图这样做:
<div id="contractContainer"> @Html.EditorFor(item=>item.ContractList,"ContractTemplate") </div>
它抛出InvalidOperationException,说我必须传递一个简单的Chkviewmodel而不是GenericList Chkviewmodel.
我只是问这个,因为我试图创建另一个复选框列表,我无法使它工作(甚至不显示复选框),当我试图设置模板名称,这样我至少可以看到复选框,它抛出了那个错误.
解决方法
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。