获取使用ViewContext视图的VirtualPath [英] Get VirtualPath of a View using ViewContext
问题描述
是否有可能找出当前ViewContext的VirtualPath如
Is it possible to figure out the current ViewContext's VirtualPath eg
〜/查看/公司/ Create.aspx
~/Views/Company/Create.aspx
推荐答案
我觉得这是你追求的:
((WebFormView) ViewContext.View).ViewPath
显然,如果您使用标准的Web表单视图引擎这仅适用(一种基于关闭问题的措辞,你是)。即在 ViewContext.View
返回 IVIEW
,这可能不是一个 WebFormView
如果您使用的是不同的视图引擎。
Obviously this only works if your using the standard web form view engine (which based off the wording of your question, you are). I.e. the ViewContext.View
returns an IView
, which may not be a WebFormView
if you're using a different view engine.
修改:顺便说一下,我已经测试了上述code,它肯定返回路径作为虚拟路径(而不是绝对或应用程序相对路径,像我起初以为这威力)。即它给你一个值是这样的:
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). I.e. it gives you a value like this:
~/Views/Company/Create.aspx
这篇关于获取使用ViewContext视图的VirtualPath的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!