简体   繁体   中英

Get VirtualPath of a View using ViewContext

Is it possible to figure out the current ViewContext's VirtualPath eg

~/Views/Company/Create.aspx

I think this is what you're after:

((WebFormView) ViewContext.View).ViewPath

Obviously this only works if your using the standard web form view engine (which based off the wording of your question, you are). Ie the ViewContext.View returns an IView , which may not be a WebFormView if you're using a different view engine.

Edit : By the way, I have tested the above code and it definitely returns the path as a virtual path (and not an absolute or app relative path, like I initially assumed it might). Ie it gives you a value like this:

~/Views/Company/Create.aspx

您可以使用此代码获取虚拟路径,

<%= HttpRuntime.AppDomainAppVirtualPath %>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM