caciocode
caciocode
CC#
Created by caciocode on 8/25/2023 in #help
❔ ASP.NET Core ignoring custom DynamicRouteValueTransformer
I have created a custom DynamicRouteValueTransformer to help me switch between 2 controllers and actions but the route values are not being used by ASP.NET Core. Here is how the tranform looks;
public class UserModeTransformer : DynamicRouteValueTransformer
{
/*public readonly ApplicationDbContext _context;

public UserModeTransformer(ApplicationDbContext context)
{
_context = context;
}*/

public override async ValueTask<RouteValueDictionary> TransformAsync(HttpContext httpContext, RouteValueDictionary values)
{
values = new RouteValueDictionary();
values["area"] = "Candidate";
values["controller"] = "SocialController";
values["action"] = "Index";
return values;
}
}
public class UserModeTransformer : DynamicRouteValueTransformer
{
/*public readonly ApplicationDbContext _context;

public UserModeTransformer(ApplicationDbContext context)
{
_context = context;
}*/

public override async ValueTask<RouteValueDictionary> TransformAsync(HttpContext httpContext, RouteValueDictionary values)
{
values = new RouteValueDictionary();
values["area"] = "Candidate";
values["controller"] = "SocialController";
values["action"] = "Index";
return values;
}
}
For now I am just providing the controller and action but it is returning 404 error in the browser although the controllers and actions exist.
2 replies