MVC Razor display template

放肆的年华 提交于 2019-12-04 15:30:44
@model IEnumerable<CustomEntity>

@{
    ViewBag.Title = "Index";
}
@Html.DisplayForModel()

and then make sure that your display template is stored in ~/Views/Shared/DisplayTemplates/CustomEntity.cshtml. Notice that the location and the name of the display template is very important. It should be called the same way as the type (CustomEntity.cshtml) and should be located either in ~/Views/Shared/DisplayTemplates or you could also override it in ~/Views/XXX/DisplayTemplates where XXX is the controller that rendered the main view.

The data you pass in the Html.DisplayFor of type IEnumerable<CustomEntity>, but your DisplayTemplate requires a CustomEntity. Try this instead :

@model IEnumerable<CustomEntity>

@{
    ViewBag.Title = "Index";
}

@foreach(var customEntity in Model)
{
    @Html.DisplayFor(m => customEntity);
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!