c# - 未调用自定义编辑器模板
问题描述
我有一个使用数字 EditorTemplates 并针对 .NET Framework 4.6.1 的 MVC 应用程序。我有一个我想用来将枚举呈现为一组单选按钮,我的用户可以从中选择。
在我的 ViewModel 中,我有以下内容:
public enum ApplicationType { Register, Replace, Renew }
[UIHint("EnumRadioButtons")]
public ApplicationType AppType { get; set; }
在我看来,我正在使用
@Html.EditorForModel(Model)
我的编辑器模板看起来像:
@model Enum
var listItems = Enum.GetValues(Model.GetType()).OfType<Enum>().Select( e =>
new SelectListIten()
{
Text = getDescription(e), //Function just used to get the Display Value
Value = e.ToString(),
Selected = e.Equals(Model)
});
foreach (var li in listItems)
{
//Render the Radio Button
}
我还有另一个枚举编辑器模板,它将我的枚举呈现到下拉列表中。在为我的模型渲染 EditorModel 时,使用标准的 Enum 编辑器模板,而不是我的自定义 EnumRadioButtons 模板。有任何想法吗?
我也用过[DataType("EnumRadioButtons")]
装饰无济于事。
这在我使用这种确切的方法和特定的编辑器模板但针对 .NET Framework 4.0 之前有效。
谢谢
西蒙
解决方案
推荐阅读
- electron.net - ElectronNET 使用 dot net core 项目生成 32 位 exe 或其他自定义版本
- python - 如何处理 UFuncTypeError?
- c# - 如何检查最大数量是否大于1
- python - 使用字典的 for 循环,但仅在键是单个字符时才有效
- python - 如何将此字符串 '2012-07-06T21:00:00.000Z' 转换为日期时间格式以计算年龄
- c - 尝试在 linux C 套接字中将客户端连接到服务器时连接被拒绝
- binary-search-tree - 数据结构
- ios - 如何更改此已弃用的代码?(flutter_inappwebview)
- python - 如何在 python 中生成孟加拉语文本的 wordcloud?
- javascript - 在ndoejs和mongoose中保存数据库后返回数据时调用socket