How can I return the current action in an ASP.NET MVC view?

前端 未结 11 1763
旧巷少年郎
旧巷少年郎 2020-11-28 17:32

I wanted to set a CSS class in my master page, which depends on the current controller and action. I can get to the current controller via ViewContext.Controller.GetTy

11条回答
  •  野趣味
    野趣味 (楼主)
    2020-11-28 18:09

    In MVC you should provide the View with all data, not let the View collect its own data so what you can do is to set the CSS class in your controller action.

    ViewData["CssClass"] = "bold";
    

    and pick out this value from your ViewData in your View

提交回复
热议问题