【发布时间】:2016-06-10 08:09:58
【问题描述】:
我一直在试图弄清楚为什么我的模板没有被渲染或找到(因为模板上的断点没有被命中)。我有一个这样的模型:
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">
}
Dropdown 对象定义在哪里
public class Dropdown
{
public int SelectedValue { get; set; }
public IEnumerable<SelectListItem> Values { get; set; }
public string Placeholder { get; set; }
}
我在 Views/Shared/EditorTemplates/Dropdown.cshtml 下为 Dropdown 创建了一个编辑器模板
@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<SelectListItem> -
@StephenMuecke 谢谢,感谢每一个快捷方式:)
-
@NightOwl888 已经尝试使用 UIHint 强制使用没有结果的模板
-
尝试更改您的班级名称。
Dropdown可能是一个保留字,因为在 MVC 框架中已经有一个名为Dropdown的类。
标签: c# asp.net-mvc templates mvc-editor-templates editorformodel