错误类型:为@ Html.EditorFor(model => model.Items)输出false false false
预期结果:具有用户名称的列表框。
public class NewVariance
{
MVRLinqDataContext LinqCtx = new MVRLinqDataContext()
public NewVariance()
{
IndividualsObjectTest();//load data dropdown and listbox data
}
public MultiSelectList Items { get; set; }
//loads the values of the MultiSelectList above
public void IndividualsObjectTest()
{
var IndividualsDropDownList =
(
from x in LinqCtx.ViewIndividualDropDownBoxes
orderby x.FullName
select x);
Items = new MultiSelectList
(
IndividualsDropDownList as
System.Collections.IEnumerable, "First_Hospital_Case_Nbr", "FullName"
);
}
public class NewVarianceController : Controller
{
public ActionResult Index()
{
var model = new NewVariance();
return View(new model);
}
}
@Html.ListBox("d",Model.Items) THIS WORKS
@Html.EditorFor(model => model.Items) THIS DOESNT WORK OUTPUTS FALSE FALSE FALSE
答案 0 :(得分:3)
编辑器模板只根据属性类型呈现一些default output。如果你希望做一些有用的事情,你需要个性化它。您可以在this blog post上阅读有关模板化助手的更多信息。您不能指望默认编辑器模板会知道您希望它为此给定属性呈现列表框。因此,您可以编写自定义编辑器模板并个性化此行为。