Skip to content

IRouter.GetVirtualPath alternative in EndpointRouting #23041

Open
@alienwareone

Description

@alienwareone

Based on this topic:
#18883

The "IRouter.RouteAsync" alternative is "DynamicRouteValueTransformer.TransformAsync".

What is the "VirtualPathData GetVirtualPath(VirtualPathContext context)" alternative for complex url generation?

For example:

public override VirtualPathData GetVirtualPath(VirtualPathContext context)
{
  var routeContext = context["context"] as new ProductListRouteContext();
  var pathSegements = new List<string>();
  if (context?.Category?.PageName != null)
  {
    pathSegments.Add(context.Category.PageName);
  }
  // Add other pathSegements based on the context/filters...
  return new new VirtualPathData(this, string.Join("/", pathSegments));
}

In my view:

Url.RouteUrl("ProductList", new { context = Model.ProductListRouteContext });

Metadata

Metadata

Assignees

No one assigned

    Labels

    Priority:1Work that is critical for the release, but we could probably ship withoutaffected-very-fewThis issue impacts very few customersarea-mvcIncludes: MVC, Actions and Controllers, Localization, CORS, most templatesenhancementThis issue represents an ask for new feature or an enhancement to an existing onefeature-routingseverity-majorThis label is used by an internal tool

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions