November Happy Hour will be moved to Thursday December 5th.
AI OnAI Off
November Happy Hour will be moved to Thursday December 5th.
Intresting in why would you add partial routing on startpage? what is the scenario here? Why not just route everyting to startpage controller?
endpoints.MapControllerRoute(name: "everygthingystart", pattern: "{id?}", defaults: new { controller = "StartPage", action = "Index" });
@Dzung
So I finally got it to work here is the what I found in the documentation.UrlResolverContext.RouteValues
in RoutePartial
method reflects HttpContext.RouteValues
, which is unchangeable in ASP Net Core.
To add additional data to RouteValues
you must use IHttpContextAccessor.HttpContext.Items
or IHttpContextAccessor.HttpContext.Request.RouteValues
. For example:
public class NewsPartialRouter : IPartialRouter<NewsContainer, NewsContent>
{
private readonly IHttpContextAccessor _contextAccessor;
public object RoutePartial(NewsContainer content, UrlResolverContext urlResolverContext)
{
_contextAccessor.HttpContext.Request.RouteValues.Add("paramName", paramValue);
// or
_contextAccessor.HttpContext.Item.Add("paramName", paramValue);
// MVC controller will be:
// public IActionResult Index(NewsContainer currentContent, object paramName)
}
}
Hi Optimizely team,
I'm trying implement custom PartialRouter follow this Developer guide - Routing and seem it's not working.
I created CustomPartialRouter as bellow:
Registed in DI and called UseTemplate as bellow
Updated StartPageController to pass string parameter named "id" as bellow
And when debug, I saw custom PartialRouter setted routesValues before go to StartPageController, but parameter still empty as image bellow:
Did you find a solution for the Partial router not working ?
I have the exact same issue where I add a value to the RouteValues and can see them in Partial router but as soon as I return the content and come to the controller that added routeValue is not there.
Not found any solution to make Partial router work. So I registered all custom route via Startup like @Luc's comment.
Using custom routes in Startup makes the Parital Router useless. For me this is a issue when upgrading from CMS 11 to 12.
I'll ask around a bit and let you know if I find a soultion to this :)
I got it it to work. You can see my comment on the post.
Hope it works for you as well :)