I want to get the current route name in my html helper but I don't know how to make it.
I thinks the solution is in this post post but I don't know how to create the RouteCollectionExtions.
For the moment my code is:
using System; using System.Collections.Generic; using System.Globalization; using System.Linq; using System.Web; using System.Web.Mvc; using System.Web.Routing; public static class RouteCollectionExtensions { public static Route MapRouteWithName(this RouteCollection routes, string name, string url, object defaults, object constraints) { Route route = routes.MapRoute(name, url, defaults, constraints); route.DataTokens = new RouteValueDictionary(); route.DataTokens.Add("RouteName", name); return route; } } public class RouteConfig { public static void RegisterRoutes(RouteCollectionExtensions routes) { routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); routes.IgnoreRoute("favicon.ico"); // Default routes.MapRoute ("Default", "", new { controller = "Home", action = "Index", id = UrlParameter.Optional }); outes.MapRouteWithName("HomeFr", "fr", new { controller = "Home", action = "Index" }); } }
Do you know why the compiler says:
'MyNamespace.RouteCollectionExtensions' does not contain a definition for 'MapRoute' and the best extension method overload 'System.Web.Mvc.RouteCollection.Extensions.MapRoute(System.web.Routing.RouteCollection, string, string, string[])' has some invalid arguments.
Thanks you for your help. Regards,