MVC template from folder other than default (EditorTemplates/DisplayTemplates)?

后端 未结 3 1940
鱼传尺愫
鱼传尺愫 2020-12-14 00:03

Can you point MVC to a folder other than the default ones (Views/Shared/EditorTemplates & Views/Shared/DisplayTemplates)? I\'d like to either put them in subfolders bel

3条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-14 00:07

    If you do this:

    @Html.EditorFor(x => x.Foo, "Order/ProductModel")
    

    it won't parse Foo as a collection and apply your editor template to each item. It will rather assume that your editor template should be applied to the collection as a whole.

    If you want to apply editor template to each item individually, just place it in EditorTemplates folder under your view folder (as it will have precedence) and use the default syntax:

    @Html.EditorFor(x => x.Foo)
    

    Of course, the name of the editor template has to match the type of items in your collection.

提交回复
热议问题