I have the following method returning html-code for a model according to the PropertyInfo
referencing TDatas
property.
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);
}
The name of the displaytemplate is defined via UIHint and is read out correctly.
So one call could be:
return helper.Display("Name", "NameDisplayTemplate");
Unfortunatly the templatename
parameter is ignored when I want to render the property with a specific DisplayTemplate. I tried both displaytemplate (folder displaytemplate) and partialview. None of them worked.
Someone any ideas?
The problem was that the template has to be placed in the DisplayTemplates-Folder, as it is written in the msdn.
If a template whose name matches the templateName parameter is found in the controller's DisplayTemplates folder, that template is used to render the expression. If a template is not found in the controller's DisplayTemplates folder, the Views\Shared\DisplayTemplates is searched for a template that matches the name of the templateName parameter. If no template is found, the default template is used.