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

后端 未结 3 1933
鱼传尺愫
鱼传尺愫 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:18

    No, I am afraid you can't do this.

    For example, if I have an editor template under this folder

    That's no longer an editor template. It's a partial. If you want to share editor templates between different controllers you can simply put them inside the ~/Views/Shared/EditorTemplates folder.

    As far as subfolders are concerned then you could do this:

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

    which will render the ~/Views/CurrentController/EditorTemplates/Order/ProductModel.cshtml or ~/Views/Shared/EditorTemplates/Order/ProductModel.cshtml editor template.

提交回复
热议问题