How to work with Razor _layout menu items

While using Razor in an MVC4 application I was working on, I needed to 'enable' the menu item for the current page.

The solution turned out to be quite simple (when I thought about it)

in the _Layout.cshtml add the following script

            public string Selected(string PageTitle)
                if (ViewBag.Title == PageTitle)
                    return "current";
                    return "";
Then call the function from  HTML
<li class="@Selected("Dashboard")">
                            <a href='@Url.Action("Index", "Dashboard")'>
                                <img src="~/img/computer.png" width="25" height="25">Dashboard</a>
<li class="@Selected("Reports")">
                            <a href='@Url.Action("Index", "Reports")'>
                                <img src="~/img/chart.png" width="25" height="25">Reports</a>
Finally in each view you will can define the page title
e.g. in Dashboard view
    ViewBag.Title = "Dashboard";