How does a Razor Layout get the name of the View using it?
My Layout displays a menu using Html.RenderAction. The Action needs the Controller name and View name passed to it so it can work out what menu options to display depending on the user's profile and the page they are on. I can obtain the Controller name using ViewContext.Controller.ToString() but can't find an equivalent for the View that is using the Layout. It must be there somewhere, but I've run out of guesses. I know I could put it in the ViewBag for each View, but that depends on remembering to do it every time, which I am now too old and tired to depend on.开发者_运维问答
Can you tie it to the action instead of the view being rendered? You can get the action from the RouteData on the ViewContext.
var action = ViewContext.RouteData["action"] as string;
精彩评论