I would like to, especially in a debug build config for example, like to have views and partial views emit their file names into the mark-up that they render. Is there some easily available view property I can use? Or would I have to override something like the View method in a derived controller to push this data into the view as it’s being rendered?
Aside: At present I derive all my view models from ViewModelBase, so this may be one vector of getting this information to the rendered HTML, but I don’t know where to start.
EDIT: James’s answer below is perfect in telling me where to get the information, and how to render it, but I would appreciate some suggestions on how to incorporate this information in all views and partials. I realize I will probably have to resort to some low level framework coding, such as adding an overload of RenderPartial that renders a container element that I can tag the view name onto, such as in my first pass solution of doing the following in my master layout and views:
_Layout.cshtml:
<section id="main" data-viewname="@(ViewBag.BodyViewName)">
@RenderBody()
</section>
[AllViews].cshtml:
@{
ViewBag.BodyViewName = this.VirtualPath;
ViewBag.Title = "My Courses";
}
You can use the
VirtualPathproperty that is a member of the WebPageBase class that represents a razor page. Inside of your view or partial view you can access this class and display its property like so:Edit:
For the aspx view engine you can use this: