Display template is a html template which can be repeat for each item in its model and it will load in specific section of a view of asp.net web application. A template can have styles/scripts or Razor codes in itself also.
Questions tagged [display-templates]
102 questions
48
votes
4 answers
ASP.net MVC - Display Template for a collection
I have the following model in MVC:
public class ParentModel
{
public string Property1 { get; set; }
public string Property2 { get; set; }
public IEnumerable Children { get; set; }
}
When I want to display all of the…

Dismissile
- 32,564
- 38
- 174
- 263
30
votes
1 answer
In an Editor Template call another Editor Template with the same Model
I have an editor template and within that editor template i want to call another editor template with the same model (i.e. nested), but it does not seem to display.
ie. \EditorTemplates\Template1.cshtml
@model foo
// insert code here to edit the…

tkerwood
- 1,875
- 16
- 26
24
votes
2 answers
Using a DisplayTemplate (with DisplayFor) for each item in a collection
I have created a DisplayTemplate for a Comment class, and placed it inside Comment/DisplayTemplates/Comment.cshtml.
Comment.cshtml is properly typed:
@model Comment
Then, I have a partial view that takes an IEnumerable for model. In there…

Sergi Papaseit
- 15,999
- 16
- 67
- 101
23
votes
5 answers
How do I override DisplayFor boolean?
How do i create a display template so i can display a bool as Yes or No not a checkbox? Using mvc3
<%: Html.DisplayFor(model => model.SomeBoolean)%>

newbie_86
- 4,520
- 17
- 58
- 89
14
votes
4 answers
MVC 3 multiple DisplayFor-Templates
I'm trying to make a custom template for a basket item list. I need a few different templates, as I have different ways of displaying the item, depending on if it's on the webpage or in a mail. Now my problem is, that when I use the default name it…

Nischo
- 454
- 6
- 20
12
votes
2 answers
How to prevent Razor from adding prefixes to inputs when using nested display templates?
When I use nested display templates and add input elements through the HTML helper the Razor engine adds a prefix to the fields names.
I do understand this is done to guarantee input name uniqueness at page level (and to rebuild the whole model on…

Albireo
- 10,977
- 13
- 62
- 96
10
votes
2 answers
Pass Additional ViewData to DisplayFor Template
I want to pass an object Model.AvailableVerticalType along with the
expression and templateName in the call to the HTML Helper DisplayFor.
Without passing the object, the DisplayFor() syntax looks like this:
@Html.DisplayFor(o => offer,…

Multi stack
- 311
- 3
- 9
- 18
9
votes
1 answer
Sharepoint: How to show AppendOnlyHistory on a display template in a cross-publishing scenario
The overarching requirement I am trying to implement is to show comments (made on a list, item by item basis).
I added the feature on the authoring side by enabling versioning on the list and adding a text field with the option "Append Changes to…

sergio
- 1,026
- 2
- 19
- 43
9
votes
1 answer
ASP.NET MVC 4 define display template for string only
I want to create a display template for string properties only, and use default for all others.
I tried to make a string.cshtml in Views/Shared/DisplayTemplates with following contents:
@model string
@Html.TextBoxFor(m => m, new { @readonly =…

Goran Obradovic
- 8,951
- 9
- 50
- 79
8
votes
3 answers
ASP.NET MVC 3 Custom Display Template With UIHint - For Loop Required?
If i have a ViewModel like this:
public class MyViewModel
{
[UIHint("SomeTemplate")]
public ICollection Submodel { get; set; }
}
And a strongly-typed View with a line of HTML like this:
@Html.DisplayFor(model =>…

RPM1984
- 72,246
- 58
- 225
- 350
8
votes
5 answers
Freemarker does not assign staticUtil
I worked Application Display Templates on liferay 6.2, I use freemarker help pagination the dynamics data list of liferay. When I upgrade to liferay 7, it is a problem. Liferay 7 use code <#assign records =…

lee trj
- 83
- 1
- 5
7
votes
0 answers
How to use DisplayTemplates in MVC core 2.0
I used to use DisplayTemplates in MVC5 to get rid off foreach loops from views
If I have a ProductDto and ProductController
I would place a ProductDto.cshtml under
Views/Product/DisplayTemplates/
or
Views/Shared/DisplayTemplates/
to use the…

akd
- 6,538
- 16
- 70
- 112
7
votes
1 answer
ASP.NET MVC Display Template for strings is used for integers
I recently hit an issue with ASP.NET MVC display templates. Say this is my model:
public class Model
{
public int ID { get; set; }
public string Name { get; set; }
}
this is the controller:
public class HomeController : Controller
{
…

Atanas Korchev
- 30,562
- 8
- 59
- 93
6
votes
1 answer
How to use DisplayTemplates in ASP.Net Core Razor Pages with Model Inheritance?
Trying to get DisplayTemplates in ASP.Net Core 2.2 to work with classes that inherit from a base class similar to this question How to handle an entity model with inheritance in a view?
The Principal DisplayTemplate is being used for all items in…

mheptinstall
- 2,109
- 3
- 24
- 44
6
votes
4 answers
ASP.NET MVC 3 Generic DisplayTemplates
I've just started a project using ASP.NET MVC 3. I'm building on top of an existing object system, so one of the first things I have to do is define display and editor templates for the various types that exist.
Is it possible in MVC to define a…

LorenVS
- 12,597
- 10
- 47
- 54