RollerCosta
RollerCosta

Reputation: 5176

How to get the current viewName(not action name) in ASP .NET MVC3(beta)

I want to use Internationalization for that i need current viewname(not actionname) so that i can accordingly display specific view for that selected culture.

protected override void OnActionExecuted(ActionExecutedContext filterContext)
    {
          string cultureName = Thread.CurrentThread.CurrentCulture.Name;
        //String ViewNameOnly= do something to get viewName 
         if (string.IsNullOrEmpty(ViewNameOnly))
            ViewNameOnly= filterContext.RouteData.Values["action"] + "." + cultureName;

    }

Upvotes: 1

Views: 1875

Answers (2)

Jeroen
Jeroen

Reputation: 837

protected override void OnActionExecuted(ActionExecutedContext filterContext)
{
    ViewResultBase view = filterContext.Result as ViewResultBase;
    if (view != null) {
        string viewName = view.ViewName;
    }
}

Upvotes: 2

harriyott
harriyott

Reputation: 10645

filterContext.Result will contain the result returned from the controller action. This is an ActionResult which is a base class for the various results. If it is a ViewResultBase (or one of its derived types), then the ViewName property will give you what you need.

Upvotes: 1

Related Questions