Sunday, January 30, 2011

Finding the Current View in ASP.NET MVC


public static string GetCurrentView(this HtmlHelper helper)
{
string controller = helper.ViewContext.RouteData.GetRequiredString("controller");
string view = helper.ViewContext.RouteData.GetRequiredString("action");

return controller + "_" + view;

}

Ex : string currentView = Html.GetCurrentView();

No comments:

Post a Comment