When the Display, DisplayFor<T>, or DisplayForModel HTML helper methods are called, the ASP.NET Core framework renders the target property (or model) value in a way that is specific to that property (or model class) and can be affected by its metadata. For example, ModelMetadata.DisplayFormatString is used for rendering the property in the desired format. However, suppose we want a slightly more complex HTML—for example, in the case of composite properties. Enter display templates!
Display templates are a Razor feature; basically, they are partial views that are stored in a folder called DisplayTemplates under Views\Shared and their model is set to target a .NET class. Let's imagine, for a moment, that we have a Locationclass that stores the Latitude and Longitude values:
public class Location
{
public decimal Latitude { get; set; }
public decimal Longitude { get; set; }
}
If we want to have a custom display template...