Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find what ASP.NET MVC controller in master view

Tags:

asp.net-mvc

I have a shared master view for all my other views. It's in this master view I show the menu. Now I need to find out in what controller I'm currently in so I can disable/enable certain menu options.

For example it should be possible to press the "foo" link if I'm current in the "foo" controller.

How Can I do this?

like image 430
Riri Avatar asked Sep 15 '09 13:09

Riri


2 Answers

You can find it with the viewcontext

like image 122
CD.. Avatar answered Sep 21 '22 22:09

CD..


Could you use?

<%=Html.ViewContext.RouteData.GetRequiredString("controller") %>

Kindness,

Dan

like image 30
Daniel Elliott Avatar answered Sep 19 '22 22:09

Daniel Elliott