如何在 ASP.Net MVC 中找到哪个视图调用了哪个部分视图
我想创建一个调试辅助函数,可以在 MVC 部分视图中使用该函数,该函数将显示渲染调用层次结构。
例如,如果我放置
<%=Html.ShowRenderPath() %>
在名为 endpoint.ascx 的部分中,并且从另一个视图(midpoint.ascx)调用它
<% Html.RenderPartial("endpoint") %>
,并且这是从另一个视图(index.aspx)调用,
<% Html.RenderPartial("midpoint") %>
我希望辅助函数写出:
〜/views/测试/index.aspx -> 〜/views/test/midpoint.ascx -> ~/views/test/endpoint.ascx
任何人都可以为我指出正确的方向,以获取渲染部分等的视图吗?
这样我就可以调试一个已经存在的使用许多渲染空间的 MVC 应用程序,如果我们可以看到这些渲染路径,那就容易多了。
I would like to create a debugging helper function which I can use within an MVC partial view that will show what the rendering call hierarchy is.
For example if I place
<%=Html.ShowRenderPath() %>
in my partial called endpoint.ascx and it is called from another view (midpoint.ascx) using
<% Html.RenderPartial("endpoint") %>
and this was called from another view (index.aspx)
<% Html.RenderPartial("midpoint") %>
I want the helper function to write out :
~/views/test/index.aspx -> ~/views/test/midpoint.ascx -> ~/views/test/endpoint.ascx
can anyone point me in the right direction for getting the view which rendered a partial and so on?
This is so I can debug an already existing MVC app which uses many renderpatials and it would be much easier if we could see these rendering paths.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用 StackTrace 生成堆栈跟踪。从中您可以识别嵌套视图/部分视图类(以及其他内容)。您应该能够通过命名空间将视图与框架代码分开。
Use
StackTrace
to generate a stack trace. From that you can identify the nested view/partial view classes (amongst other stuff). You should be able to separate out your views from the framework code through the namespaces.感谢您的回复(为您的努力点赞:-),
我们找到的解决方案是更新我们的自定义视图引擎以输出 HTML 注释,这些注释指示每个视图的源,从而在源视图中给出页面构造的详细信息。这仅在调试模式下输出。
Thanks for the reply (upvote for your efforts :-)
the solution we have found instead was to update our custom view engine to output HTML comments which indicate the source of each view thereby giving a breakdown of the page construction in the source view. This was only outputted in debug mode.