How to add and use a razor editor template

I tried to find documentation or samples on how to include razor editor templates in a project. The following answer to another thread may solve the problem that I have, but I do not know how to include it in my project. This is without a doubt easy.

here is a solution that I don’t know how to enable: Client side validation of input date does not work

+6
source share
2 answers

Here's a summary of adding EditorTemplate . In short, you need to create the EditorTemplates directory in Views / Shared, and you must create a view with the same name as the model for which you want to create an editor.

Remember that the EditorTemplate for the model is used when calling Html.EditorFor with an object of this model as an argument. Of course, you should use them to provide editing capabilities - if you want to create something that should only display data, use the same method to create the DisplayTemplate (create the DisplayTemplates directory). DisplayTemplate mapped to an Html.DisplayFor call with an object of this model as an argument.

+8
source

There is a useful background on default templates used by Html.Editor (For) and Html.Display (For) and how to override them using the views in the / Shared / EditorTemplates view and in the View / Shared / DisplayTemplates directory of your project here .

I have a GitHub project containing Razor replacements for all default display and editing templates. Take a look at the demo web application - it should help you understand how everything fits together. Then copy the templates to your project and change the details you need.

+7
source

All Articles