title: How to Highlight navbar Menu Items in using TagHelpers (Asp.Net.MVC6 6.0.0-rc1.0-final)
body: <p>I want to generate class="active" in menu links in asp.net 5 1.0.0-rc1-final, to highlight the active menus of the navbar in _Layout.cshtml.<br>
  The solution proposed here: <a href="http://techiejourney.com/custom-taghelper-to-highlight-current-selected-menu-in-mvc-6/" rel="nofollow" title="&#40;original post byPrashant Adepu&#41;">Original post by Prashant Adepu</a> works fine in Asp.Net.MVC 6.0.0 beta5. 
  However in <strong>6.0.0 rc1 (asp.net 1.0.0 rc-1 final)</strong>, it seems <strong>impossible to use [ViewContext]</strong> decoration since this attribute does not exist.<br>
   Is there a way around this?</p>
  
  <p>1) Below is the code with minor adaptation to rc-1.<br>
  Everything works except for <strong>[ViewContext] which is rejected</strong>. Without this attribute, the viewContext will be null in runtime).<br>
  2) <strong>To run</strong> it you should create an asp.net5 WebApplicationX, and add <code>@addTagHelper "WebApplicationX.TagHelpers.MenuLinkTagHelper, WebApplicationX"</code> in _ViewImports.cshtml.<br>
    Then just use <code>&lt;menulink controller-name="Home" action-name="About" menu-text="About"&gt;&lt;/menulink&gt;</code> instead of a regular mvc <code>&lt;a asp-controller="Home" asp-action="Index"&gt;Home&lt;/a&gt;</code> Anchor.</p>
  
  <pre><code>using Microsoft.AspNet.Mvc;
  using Microsoft.AspNet.Mvc.Rendering;
  using Microsoft.AspNet.Razor.Runtime.TagHelpers;
  using Microsoft.AspNet.Razor.TagHelpers;
  using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  using System.Threading.Tasks;
  
  namespace WebApplicationX.TagHelpers
  {
      [HtmlTargetElement("menulink", Attributes = "controller-name, action-name, menu-text")]
      public class MenuLinkTagHelper : TagHelper 
      {
          public string ControllerName { get; set; }
          public string ActionName { get; set; }
          public string MenuText { get; set; }
          [ViewContext]                         //*** This is not allowed.***
          public ViewContext ViewContext { get; set; }
  
          public IUrlHelper _UrlHelper { get; set; }
  
          public MenuLinkTagHelper(IUrlHelper urlHelper)
          {
              _UrlHelper = urlHelper;
          }
  
          public override void Process(TagHelperContext context, TagHelperOutput output)
          {
              StringBuilder sb = new StringBuilder();
  
              string menuUrl = _UrlHelper.Action(ActionName, ControllerName);
  
              output.TagName = "li";
  
              var a = new TagBuilder("a");
              a.MergeAttribute("href", $"{menuUrl}");
              a.MergeAttribute("title", MenuText);
              a.InnerHtml.Append(MenuText);
  
              var routeData = ViewContext.RouteData.Values;
              var currentController = routeData["controller"];
              var currentAction = routeData["action"];
  
              if (String.Equals(ActionName, currentAction as string, StringComparison.OrdinalIgnoreCase)
                  &amp;&amp; String.Equals(ControllerName, currentController as string, StringComparison.OrdinalIgnoreCase))
              {
                  output.Attributes.Add("class", "active");
              }
  
              output.Content.SetContent(a.ToString());
          }
      }
  }
  </code></pre>