Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create custom editor/display templates in ASP.NET MVC 3?

I would like to make custom editor templates for different data types in ASP.NET MVC (to use with Html.EditorFor()), including rewriting the existing templates. The ultimate goal is to create a mini-framework where each editor supports javascript notifications about being changed, and I can show a message to the user that there are unsaved changes in the page. (Maybe there's something existing already?)

I can find many questions pertaining to problems with such templates, but nowhere can I find a tutorial or manual on creating them. Where do they go? Is there any special syntax? How does a template get selected? What information is available in the template and how do I access it? Etc.

So - where can I find out all about these templates?

like image 275
Vilx- Avatar asked Mar 31 '11 08:03

Vilx-


People also ask

What is MVC editor template?

An EditorTemplate is a Razor file placed in the EditorTemplates folder: For Razor Pages apps, in the Pages/Shared/EditorTemplates folder. For MVC apps, in the Views/Shared/EditorTemplates folder or the Views/ControllerName/EditorTemplates folder.

What is templated HTML helpers in MVC?

The Html. EditorFor templated helper also renders validation logic that enforces constraints that are built into the data model or that you can add as System. ComponentModel. DataAnnotations attributes to a partial class that is associated with the data model.

What is HTML DisplayFor?

DisplayFor() The DisplayFor() helper method is a strongly typed extension method. It generates a html string for the model object property specified using a lambda expression.


1 Answers

Check and download ASP.NET MVC 3 Futures on http://aspnet.codeplex.com/releases/view/58781 and see how the default source code looks. Note: this works for MVC 4 as well.

like image 53
Gerard Avatar answered Sep 24 '22 06:09

Gerard