1

I want to create a helper that would look something like this and

namespace MvcApplication.Helpers
{
     public static class Extensions
     {
          public static string Test(this HtmlHelper helper, string routeValue1, string routeValue2)
          {
               return "Something";

          }
     }
}

Is there a way to access ViewContext.RouteData.Values from Test without passing route values as parameters? Is the only possible alternative

public static string Test(this HtmlHelper helper, ViewContext vc)
          {
               return "Something";

          }
mko
  • 6,638
  • 12
  • 67
  • 118

1 Answers1

1

it is a property of HtmlHelper class:

      public static string Test(this HtmlHelper helper)
      {
           var routeValue = helper.ViewContext.RouteData.Values["key"];
           return "Something";

      }
Marian Ban
  • 8,158
  • 1
  • 32
  • 45
  • so RouteCollection accesses ViewContext.RouteData values and keys? Helped a lot! – mko Nov 26 '14 at 11:20
  • sorry I've made a mistake you need helper.ViewContext.RouteData.Values["key"] – Marian Ban Nov 26 '14 at 12:13
  • MajoB i would appreciate your assistance on http://stackoverflow.com/questions/27402530/how-to-get-route-name-from-action?noredirect=1#comment43250970_27402530 – mko Dec 10 '14 at 14:21