Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Paul 89 posts 167 karma points
    Oct 24, 2022 @ 07:26
    Paul
    0

    SurfaceController in custom router UmbracoPageController

    Hi,

    I am trying to use a UmbracoPageController to route something that is not in Umbraco and it works as expected.

    However, I noticed that SurfaceController no longer submits to the method.

    The surface controller works if rendered via a RenderController and the routing is setup as I can get to the page.

    public class ProductPageController : UmbracoPageController, IVirtualPageController
        {
            private readonly IUmbracoContextAccessor _umbracoContextAccessor;
    
            public ProductPageController(ILogger<UmbracoPageController> logger, ICompositeViewEngine compositeViewEngine, IUmbracoContextAccessor umbracoContextAccessor) : base(logger, compositeViewEngine)
            {
                _umbracoContextAccessor = umbracoContextAccessor;
            }
    
            public async Task<ActionResult<ProductPageViewModel>> Details(string id)
            {
                var vm = new ProductPageViewModel(id);
    
                return View("ProductDetailsPage", vm);
            }
    
    
            public IPublishedContent FindContent(ActionExecutingContext actionExecutingContext)
            {
                var root = _umbracoContextAccessor.GetRequiredUmbracoContext().Content.GetAtRoot().FirstOrDefault();
    
                return root;
            }
        }
    

    And

    public class ProductController : SurfaceController
        {
            public ProductController(IUmbracoContextAccessor umbracoContextAccessor, IUmbracoDatabaseFactory databaseFactory, ServiceContext services, AppCaches appCaches, IProfilingLogger profilingLogger, IPublishedUrlProvider publishedUrlProvider) : base(umbracoContextAccessor, databaseFactory, services, appCaches, profilingLogger, publishedUrlProvider)
            {
            }
    
            [HttpPost]
            [ValidateAntiForgeryToken]
            [ValidateUmbracoFormRouteString]
            public IActionResult HandleAdd(ProductForm model)
            {
                // code goes here
            }
        }
    

    Does anyone know what's missing or surface controller don't work in that context?

    Thanks,

    Paulius

Please Sign in or register to post replies

Write your reply to:

Draft