我有以下方法根据PropertyInfo
引用TDatas
属性返回模型的 html 代码。
public MvcHtmlString GetHtml(HtmlHelper<TData> helper) {
if (PropertyInfo.IsDefined(typeof(UIHintAttribute), true)) {
UIHintAttribute uiHintAttribute = PropertyInfo.GetCustomAttributes(typeof(UIHintAttribute), true).Cast<UIHintAttribute>().FirstOrDefault();
if (uiHintAttribute != null) {
// Templatename ignored here
return helper.Display(PropertyInfo.Name, uiHintAttribute.UIHint);
}
}
return helper.Display(PropertyInfo.Name);
}
显示模板的名称通过 UIHint 定义并正确读取。
所以一个电话可能是:
return helper.Display("Name", "NameDisplayTemplate");
不幸的templatename
是,当我想使用特定的 DisplayTemplate 呈现属性时,该参数被忽略。我尝试了显示模板(文件夹显示模板)和部分视图。他们都没有工作。
有人有什么想法吗?