Override Controller action, problem with prameters.

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
1 anno tempo fa
Hi,

I think I am missing something, I've created my custom catalog controller and IRouteProvider that registers the route.  It all works as expected.  My custom method is called. The problem is that categoryId is always 0 in the overridden Category method, seems like it's not passed through.  Should I do something in addition to make it work?

public class CustomCatalogController : CatalogController
    {
        ...
        public async override Task<IActionResult> Category(int categoryId, CatalogProductsCommand command)
        {
            return await base.Category(categoryId, command);
        }
    }

public partial class RouteProvider : BaseRouteProvider, IRouteProvider
    {
        

        public void RegisterRoutes(IEndpointRouteBuilder endpointRouteBuilder)
        {
            var lang = GetLanguageRoutePattern();

            var genericPattern = $"{lang}/{{SeName}}";

            endpointRouteBuilder.MapControllerRoute(name: "Category",
                pattern: genericPattern,
                defaults: new { controller = "CustomCatalog", action = "Category" });
        }
1 anno tempo fa
No need to override RouteProvider
just 1. Override Controller Action Method
        2. Resolve Custom Controller Dependency

services.AddScoped<CatalogController, CustomCatalogController>();

1 anno tempo fa
thank you! sometimes things are simpler than one might think :)
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.