How to add and use a razor editor template

亡梦爱人 提交于 2019-12-04 05:23:38

Here is short info about adding EditorTemplate. In short words - you have to create directory EditorTemplates in Views/Shared and you should create a view with the same name as the model you want to create the editor for.

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

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

I have a project on GitHub that contains Razor replacements for all of the default display and editor templates. Have a look at the demo web application - it should help you to see how things fit together. Then, copy the templates into your project and modify the parts you need.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!