Display and Editor Templates - ASP.NET MVC


When dealing with objects in an MVC app, we often want a way to specify how that object should be displayed on any given page. If that object is only displayed on one page, we simply write HTML and CSS to lay out and style how that object should be shown to the user. However, what if that object should be shown in multiple places, with the same format? We'd need some kind of standardized layout.

ASP.NET MVC has made this kind of standardization easy to do with the inclusion of display and editor templates. Let's walk through these features.

What are Templates For?

In short, display and editor templates are used to standardize the layout shown to the user when editing or displaying certain types or classes. For example, we might want to specify that an Address object must always be displayed with the street name on its own line, then the city/state/postal code on the next line. They're a perfect way to uphold DRY principles in your MVC app.

https://www.exceptionnotfound.net/asp-net-mvc-demystified-display-and-editor-templates/

https://www.hanselman.com/blog/ASPNETMVCDisplayTemplateAndEditorTemplatesForEntityFrameworkDbGeographySpatialTypes.aspx

https://www.growingwiththeweb.com/2012/12/aspnet-mvc-display-and-editor-templates.html


Did you find this article useful?



  • Annotation for validation

    Adding Validation to our Model We'll use the following Data Annotation attributes: Required – Indicates that the property is a required...

  • Many Partial in same View

    To Display Multi Partial in same ViewYou can only return one value from a function so you can't return multiple partials from one action method.If you...