If you search for controller
and action
, you can get it like so:
string action = html.ViewContext.RouteData.Values["action"].ToString();
string controller = html.ViewContext.RouteData.Values["controller"].ToString();
string url = "~/" + controller + "/" + action;
To get the immediate view (including partial), it is like so:
var webPage = HtmlHelper.ViewDataContainer as WebPageBase;
var virtualPath = webPage.VirtualPath;
To get the first view path (the master view containing all partial views):
var viewPath = ((System.Web.Mvc.BuildManagerCompiledView)(htmlHelper.ViewContext.View)).ViewPath;