Asp.net mvc MVC,从视图内部获取母版页路径

Asp.net mvc MVC,从视图内部获取母版页路径,asp.net-mvc,master-pages,Asp.net Mvc,Master Pages,我认为,如何从视图内部获取母版页的路径 ((WebFormView)Html.ViewContext.View).MasterPath 这就行了,但不幸的是,它总是空的 那么我该如何获得它呢?我不确定您到底需要什么,但是视图应该有一个MasterPageFile属性,其中包含到MasterPage的相对路径。如果需要物理位置,可以使用MapPath <%= this.MasterPageFile %> <%= MapPath( this.MasterPageFile ) %

我认为,如何从视图内部获取母版页的路径

((WebFormView)Html.ViewContext.View).MasterPath
这就行了,但不幸的是,它总是空的


那么我该如何获得它呢?

我不确定您到底需要什么,但是视图应该有一个MasterPageFile属性,其中包含到MasterPage的相对路径。如果需要物理位置,可以使用MapPath

<%= this.MasterPageFile %>

<%= MapPath( this.MasterPageFile ) %>