Reputation: 22016
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.
Upvotes: 2
Views: 898
Reputation: 22016
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.
Upvotes: 0
Reputation: 74899
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.
Upvotes: 1