ivaylokenov / AspNet.Mvc.TypedRouting

A collection of extension methods providing strongly typed routing and link generation for ASP.NET Core MVC projects.
https://mytestedasp.net/
MIT License
485 stars 36 forks source link

Route as route value dictionary #27

Open waynebrantley opened 7 years ago

waynebrantley commented 7 years ago

The following extension was necessary for us to write on your system.web version of this library. You made classes public so that we could do extensions like this in that library. This is a preemptive attempt at making sure the same kind of classes are now exposed publicly in this library too.

  public static RouteValueDictionary RouteValueDictionary<TController>(

               this UrlHelper helper,

               Expression<Func<TController, Task>> action,

               object routeValues = null)

           where TController : Controller

        {

            var routeInfo = RouteInformation.FromExpression<TController>(action, routeValues);

            var dictionary = routeInfo.RouteValueDictionary;

            dictionary.Add("controller", routeInfo.ControllerName);

            dictionary.Add("action", routeInfo.ActionName);

            return dictionary;

        }

Thanks!!