从default之外的文件夹MVC模板(EditorTemplates / DisplayTemplates)? [英] MVC template from folder other than default (EditorTemplates/DisplayTemplates)?

查看:344
本文介绍了从default之外的文件夹MVC模板(EditorTemplates / DisplayTemplates)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你能指出MVC到默认之外的其他文件夹(查看/共享/ EditorTemplates和放大器;查看/共享/ DisplayTemplates)?我想无论是把他们在低于,或在共享文件夹以外的其他文件夹的子文件夹。

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 below those, or in other folders outside the Shared folder.

例如,如果我有这个文件夹下的编辑模板:

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

〜\\查看\\订单\\ ProductModel.cshtml

~\Views\Order\ProductModel.cshtml

我怎么能告诉我EditorFor模板使用这个名字tempalte?

How can I tell my EditorFor template to use this tempalte name?

我试图完全限定,但是,这个不工作:

I tried fully qualifying it, but this doesn't work:

@Html.EditorFor(m => m.ProductModel, @"~\Views\Order\ProductModel.cshtml")

我一直使用正试图斜线和放大器;反斜杠,有/无.chstml,每一个组合我能想到的。我开始认为这是不支持的,但我不能想象为什么它不会是。

I've tried using forward slashes & backslashes, with/without .chstml, every combination I can think of. I'm beginning to think this isn't supported, but I can't imagine why it wouldn't be.

推荐答案

没有,恐怕你不能做到这一点。

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

例如,如果我有这个文件夹下的编辑模板

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

这不再是一个编辑模板。这是一个部分。如果你想分享不同控制器之间的编辑模板,你可以简单地将它们放在里面的〜/查看/共享/ EditorTemplates 文件夹中。

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")

这将使得〜/查看/ CurrentController / EditorTemplates /订单/ ProductModel.cshtml 〜/查看/共享/ EditorTemplates /订单/ ProductModel.cshtml 编辑模板。

这篇关于从default之外的文件夹MVC模板(EditorTemplates / DisplayTemplates)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆