How to visually indicate current page in ASP.NET MVC?

后端 未结 5 601
闹比i
闹比i 2020-12-24 03:28

As a base for discussion. Create a standard ASP.NET MVC Web project.

It will contain two menu items in the master page:

5条回答
  •  庸人自扰
    2020-12-24 03:55

    I recently created an HTML Helper for this that looks like:

    public static string NavigationLink(this HtmlHelper helper, string path, string text)
    {
        string cssClass = String.Empty;
        if (HttpContext.Current.Request.Path.IndexOf(path) != -1)
        {
            cssClass = "class = 'selected'";
        }
    
        return String.Format(@"
  • {2}
  • ", path, cssClass, text); }

    The Implementation looks like this:

      
    

提交回复
热议问题