Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MVC3: How to get currently executing view or partial view programatically inside a HtmlHelper extension?

How to get currently executing view name or partial view name programmatically inside a HtmlHelper extension? In my situation, I can't use ViewData or can't pass view name to the extension from the View.

like image 315
user785153 Avatar asked Jun 05 '11 21:06

user785153


2 Answers

var webPage = htmlhelper.ViewDataContainer as WebPageBase;
var virtualPath = webPage.VirtualPath;
like image 173
verfailliep Avatar answered Sep 28 '22 06:09

verfailliep


This is your best bet:

Retrieve the current view name in ASP.NET MVC?

like image 28
Leniel Maccaferri Avatar answered Sep 28 '22 07:09

Leniel Maccaferri