2

I am using the class DynamicRouteValueTransformer built into ASP.NET Core 3.1 to perform dynamic controller routing as demonstrated in the code below.

public class UrlRouteTransformer : DynamicRouteValueTransformer
{
    public override ValueTask<RouteValueDictionary> TransformAsync(HttpContext httpContext, RouteValueDictionary values)
    {
        var controller = "home";
        var action = "index";

        //Make decision here on which controller and action to call. i.e call the database etc

        values["controller"] = controller;
        values["action"] = action;

        return new ValueTask<RouteValueDictionary>(values);
    }
}

This code is working as expected, but I want to know how you would set data tokens?

Jeremy Caney
  • 4,585
  • 13
  • 32
  • 54
dezzy
  • 339
  • 4
  • 17

0 Answers0