I have the following code that I use to display detail rows in a grid:
foreach (var item in Model)
{
@Html.DisplayFor(model => item)
}
My model is a collection of IList<ContentDetail> and this uses the
Shared > DisplayTemplates > ContentDetail.cshtml file when it displays the items.
Is it possible for me to make it so that it uses a different file? I would like to have more than
one way of displaying the details and so I need to have more than one file.
If you look at the Intellisense in Visual Studio, the
@Html.DisplayForand@Html.DisplayForModelboth can take astring TemplateNameas an overload, where the TemplateName is the name of a partial view used to render that property or collection. The correct syntax would be:or
This should allow you to use a different file to render out your stuffs.