使用区域时如何在 MVC3 中指定共享视图的路由
我有一个使用区域的 MVC3/Razor 应用程序,这样我的视图位于以下位置:
/Areas/Areaname/Views/ControllerName/view.cshtml
现在,对于任何共享部分,我必须将它们放在这里:
/Views/Shared/_sharedview.cshtml
我更愿意这里有我的共享视图:
/Areas/Shared/Views/_sharedvew.cshtml
有没有办法告诉视图引擎查看共享视图默认位置之外的其他位置?
我在想这样的事情:
routes.MapRoute("Shared", "Areas/Shared/Views/{id}");
谢谢!
I have an MVC3/Razor app using Areas such that my views are in the following location:
/Areas/Areaname/Views/ControllerName/view.cshtml
Right now, for any shared partials, I have to put them here:
/Views/Shared/_sharedview.cshtml
I would prefer to have my shared views here:
/Areas/Shared/Views/_sharedvew.cshtml
Is there a way to tell the view engine to look somewhere other than the default location for shared views?
I am thinking something like this:
routes.MapRoute("Shared", "Areas/Shared/Views/{id}");
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我通常从 VirtualPathProvider 继承一个类,
请在这里查看更多信息:
http: //coderjournal.com/2009/05/creating-your-first-mvc-viewengine/
然后在启动中注册它:
您不必处理超出您范围的路径,因为您可以通过基本定义上的函数就像我在此嵌入式视图路径提供程序中所做的那样:
I usually descend a class from VirtualPathProvider
Have a look here for more:
http://coderjournal.com/2009/05/creating-your-first-mvc-viewengine/
then register it in the startup:
You do not have to deal with paths that are outside of your scope as you can pass the function on the the base definition as I do here in this embedded view path provider: