确定MVC3的Razor视图的物理位置 [英] Determine physical location of Razor view in MVC3
问题描述
我已经创建了自己的Razor视图类,即:
I've created my own Razor view class, thus:
public abstract class MyWebViewPage : System.Web.Mvc.WebViewPage
{
public MyWebViewPage()
{
}
}
我使用这个类在我CSHTML文件,这样的:
I use this class in my cshtml file, thus:
@inherits MyWebViewPage
<html>
...
</html>
我要确定在类的构造函数的CSHTML文件的物理位置,但似乎不能够得到在基类可能会告诉我什么的句柄。任何想法?
I want to determine the physical location of the cshtml file in the constructor of the class, but don't seem to be able to get a handle on anything in the base class that might tell me. Any ideas?
我试图找出该视图的区域名称和文件夹名称(例如地区/ MyArea /查看/ MyViews / MyView.cshtml)。相关的位为MyArea和MyViews
I'm trying to work out the Area name and folder name of the view (e.g. Areas/MyArea/Views/MyViews/MyView.cshtml). The pertinent bits being "MyArea" and "MyViews".
我目前正在移植到刀片使用意见的申请,我曾经是能够做我的需要,因为该视图的类名是沿着线的东西:
I'm currently porting an application to use Razor views and I used to be able to do what I needed because the class name of the view was something along the lines of:
ASP_Areas_MyArea_Views_MyViews_MyView
ASP_Areas_MyArea_Views_MyViews_MyView
但随着剃刀它只是:
ASP_MyView
ASP_MyView
推荐答案
您应该能够看的 VirtualPath属性。这将不可用时,构造函数调用,但你可以重写
ConfigurePage
和做任何处理那里。
You should be able to look at the VirtualPath
property. It will not be available when the constructor gets invoked, but you can override ConfigurePage
and do any processing there.
这篇关于确定MVC3的Razor视图的物理位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!