3

This is probably easy, although I cant seem to find the solution. In my view I have links in a partial view which acts as a menu. I need to apply an active class to the anchors if they are the page currently being viewed.

What I therefore need is a quick and simple method of checking the href of the link against the url of the page?

Any takers? :)

Sergio
  • 9,761
  • 16
  • 60
  • 88

1 Answers1

3
RouteData.GetRequiredString("action")

will give you the action that was used to render this view. As far as good practices are concerned I would recommend you writing an HTML helper that will do the job instead of polluting your views with C#.

Community
  • 1
  • 1
Darin Dimitrov
  • 1,023,142
  • 271
  • 3,287
  • 2,928