开发者

How does a Razor Layout get the name of the View using it?

开发者 https://www.devze.com 2023-02-16 09:09 出处:网络
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

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;
0

精彩评论

暂无评论...
验证码 换一张
取 消