How can I get the name of the view on the main page

Essentially, the question is in the title. I have an ASP.NET MVC application and I need to get and use the name of the view in the master page.

For example, I might want to include "viewname" .js in the title of each page, or use it in a RenderAction call. Of course I can create an asp: ContentPlaceHolder in the main section of the master page, but I noticed that the content I put in the views is all the same except for the view name itself. So I'm trying to refactor and I don't see anything useful in either page or any ViewXXX variables.

thank

+2


source to share


1 answer


You should be able to get the name of the view:



IView view = ((ViewPage)this.Page).ViewContext.View;
string viewname = ((WebFormView)view).ViewPath;

      

+2


source







All Articles