集团MVC3意见纳入下的主要“动作”文件夹的子文件夹 [英] Group MVC3 views into sub-folders under main 'action' folder
问题描述
例如。我有三种付款控制器,每个特定的第三方支付处理器,所以在我的根视图文件夹,我对每个控制器一个文件夹。我想这些进入查看\\付款\\处理器1,查看\\付款\\分享帮助等,而不是当前视图\\处理器1等。
E.g. I have three payment controllers, each specific to a third party payment processor, so under my root Views folder, I have one folder for each of these controllers. I would like to move these into Views\Payments\Processor1, Views\Payments\Processor2, etc. instead of the current Views\Processor1 etc.
我不准备实施的区域,所以我很希望有一些方法,我可以告诉MVC也看在子文件夹,或者类似的东西。可以这样做,以及如何?
I am not ready to implement areas yet, so I'm hoping there is some way I can tell MVC to also look in subfolders, or something like that. Can this be done and how?
推荐答案
您可以编写一个自定义视图引擎和<一个href=\"http://weblogs.asp.net/imranbaloch/archive/2011/06/27/view-engine-with-dynamic-view-location.aspx\">override默认视图位置的:
You could write a custom view engine and override the default view locations:
public class MyRazorViewEngine : RazorViewEngine
{
public MyRazorViewEngine() : base()
{
base.ViewLocationFormats = base.ViewLocationFormats.Concat(new[] {
"~/Views/Payments/{1}/{0}.cshtml",
"~/Views/Payments/{1}/{0}.vbhtml"
}).ToArray();
base.PartialViewLocationFormats = base.PartialViewLocationFormats.Concat(new[] {
"~/Views/Payments/{1}/{0}.cshtml",
"~/Views/Payments/{1}/{0}.vbhtml"
}).ToArray();
}
}
,然后在的Application_Start
注册它:
ViewEngines.Engines.Add(new MyRazorViewEngine());
这篇关于集团MVC3意见纳入下的主要“动作”文件夹的子文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!