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);
}
}
}
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.
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);
}
}
Exception when implementing RenderController
All my attempts at implementing RenderController end up in the same error. Im using Umbraco version 9.0.0-beta001
This is what my code looks like
Have i misunderstood how to hijack routs?
I had this same issue. The problem was that the Index method didn't have the override modifier.
should be:
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?
You should not override when you are using querystrings as mentioned in the article you linked too :)
ha I saw that and thought I was missing something, didn't notice the method attribute! thanks for error checking my stupidity
is working on a reply...