Copied to clipboard

Flag this post as spam?

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


  • Niklas Fanghol 4 posts 73 karma points
    Aug 03, 2021 @ 06:08
    Niklas Fanghol
    0

    Exception when implementing RenderController

    All my attempts at implementing RenderController end up in the same error. Im using Umbraco version 9.0.0-beta001

    An unhandled exception occurred while processing the request.
    AmbiguousMatchException: The request matched multiple endpoints. Matches:
    
    Unicore.Controllers.PageController.Index (Unicore)
    Unicore.Controllers.PageController.Index (Unicore)
    
    Microsoft.AspNetCore.Routing.Matching.DefaultEndpointSelector.ReportAmbiguity(CandidateState[] candidateState)
    

    This is what my code looks like

    using Microsoft.AspNetCore.Mvc;
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Threading.Tasks;
    using Microsoft.AspNetCore.Mvc.ViewEngines;
    using Microsoft.Extensions.Logging;
    using Umbraco.Cms.Core.Models;
    using Umbraco.Cms.Core.Models.PublishedContent;
    using Umbraco.Cms.Core.Web;
    using Umbraco.Cms.Web.Common.Controllers;
    
    namespace Unicore.Controllers
    {
        public class PageController : Umbraco.Cms.Web.Common.Controllers.RenderController
        {
            public PageController(ILogger<RenderController> logger, ICompositeViewEngine compositeViewEngine, IUmbracoContextAccessor umbracoContextAccessor) : base(logger, compositeViewEngine, umbracoContextAccessor)
            {
            }
            public IActionResult Index(ContentModel<IPublishedContent> model)
            {
                return View("/Views/Page.cshtml", model);
            }
        }
    }
    

    Have i misunderstood how to hijack routs?

  • Matt W 1 post 74 karma points
    Sep 02, 2021 @ 23:54
    Matt W
    3

    I had this same issue. The problem was that the Index method didn't have the override modifier.

    public IActionResult Index(...)
    

    should be:

    public override IActionResult Index(...)
    
  • David Harlow 2 posts 72 karma points
    Mar 02, 2022 @ 11:27
    David Harlow
    0

    This solved the issue to an extent, but now when I wish to access query parameters as you should be able to like this, the project will no longer build as there is "no suitable method to override" as you'd expect.

    Seems like a bug, has anyone found a solution?

  • Bo Jacobsen 606 posts 2404 karma points
    Mar 02, 2022 @ 12:19
    Bo Jacobsen
    0

    You should not override when you are using querystrings as mentioned in the article you linked too :)

    public class ProductListingPageController : Umbraco.Cms.Web.Common.Controllers.RenderController
    {
       //notice how we are no longer overriding the Index action because the signature is now different to the base signature.
        [HttpGet]
        public IActionResult Index([FromQuery(Name = "page")] int page, [FromQuery(Name = "andAnotherThing")] string andAnotherThing)
        {
           var products = _madeUpProductService.GetProductsByPage(page);
           var productListingViewModel = new ProductListingViewModel(CurrentPage, new PublishedValueFallback(_serviceContext, _variationContextAccessor));
           productListingViewModel.Products = products;
           productListViewModel.Thing = andAnotherThing;
    
           return CurrentTemplate(productListViewModel);
        }
    }
    
  • David Harlow 2 posts 72 karma points
    Mar 02, 2022 @ 12:28
    David Harlow
    0

    ha I saw that and thought I was missing something, didn't notice the method attribute! thanks for error checking my stupidity

Please Sign in or register to post replies

Write your reply to:

Draft