我被困在试图弄清楚为什么我的模板没有被呈现或找到(因为模板上的断点未被命中)。我有一个模型是这样的:ASP.NET MVC未找到/使用自定义类型编辑器模板
public class SomeModel
{
public Dropdown Cities { get; set; }
}
在该视图
@model Mvc.Models.SomeNamespace.SomeModel
@{
Layout = "../Shared/_Site.cshtml";
}
@Html.ValidationSummary(true)
@using (Html.BeginForm())
{
@Html.EditorForModel()
<input type="submit" value="Continue">
}
在下拉对象定义
public class Dropdown
{
public int SelectedValue { get; set; }
public IEnumerable<SelectListItem> Values { get; set; }
public string Placeholder { get; set; }
}
我下创建一个编辑模板使用下拉Views/Shared/EditorTemplates/Dropdown.cshtml
@model Mvc.ViewModels.Dropdown
@Html.DropDownListFor(model => model.SelectedValue, Model.Values, Model.Placeholder)
对我来说令人震惊的是,我在该路径下还有DateTime.cshtml模板,工作得很好。
除了Dropdown类型的属性,模型中的每个属性都被渲染,即使是带有自定义模板的DateTime。
我不知道什么?
编辑:在Cities属性中已经尝试使用[UIHint(“Dropdown”)]。
EDIT2:尝试过重命名为DropdownViewModel
不相关,但它需要的是'@ Html.DropDownListFor(m => m.SelectedValue,Model.Values,Model.Placeholder)' - 无需创建第二个相同的'IEnumerable'从第一个 –
@StephenMuecke谢谢,每一个快捷方式是赞赏:) –
相关:[可重复使用的业务对象的DropDownList编辑器模板](http://stackoverflow.com/q/6744432/181087) – NightOwl888