18
我写了一个EnumDropDownFor()帮助器,我想和EditorFor()一起使用。我刚刚开始使用EditorFor(),因此对模板的选择有点困惑。ASP.NET MVC:使用EditorFor()和默认的枚举模板
我Enum.cshtml编辑模板低于:
<div class="editor-label">
@Html.LabelFor(m => m)
</div>
<div class="editor-field">
@Html.EnumDropDownListFor(m => m)
@Html.ValidationMessageFor(m => m)
</div>
的显式定义使用的模板短,有没有什么办法,只要有一个枚举被传递到EditorFor其中使用默认模板()?
好极了!已阅读该帖子,但没有意识到该字符串将被默认使用。这是使用的模板,如果它不能匹配其他任何东西? – ajbeaven 2011-04-16 09:38:36
Can not get it work,as @if(Model is Enum)always always returns false as the Model is alwyes null !! ..我失踪了! ... 非常感谢。 – Hossam 2011-05-31 18:27:15
应该使用@if(ViewData.ModelMetadata.ModelType.IsEnum)来代替检查实例,以便正确拾取nullabes。 – 2012-12-03 16:06:14