November Happy Hour will be moved to Thursday December 5th.

IPartialRouter and UrlResolverContext RouteValues

Vote:
 

Hi!

Have a question about CMS 12 partial routing and passing parameters around. I see that it's possible to use RouteValues, e.g. like this:

public object RoutePartial(MyDearPage content, UrlResolverContext segmentContext)
{
	var segment1 = segmentContext.GetNextSegment(segmentContext.RemainingSegments);	
	segmentContext.RouteValues["dearPageSegment1"] = segment1.Next.ToString(); //here I'm adding my things to RouteValues
	...
	return content;
}

My problem is that I don't see a way how to access these UrlResolverContext.RouteValues later on, e.g. in the PageCotroller? Anyone knows what would be the right way to use / access them? 

#298830
Mar 23, 2023 12:25
Vote:
 

Hi Janis

What if you add "dearPageSegment1" as a parameter to your action method? Like Index(string dearPageSegment1).

#298862
Mar 23, 2023 20:01
Vote:
 

Nope, unfortunately, didn't work :/. Found a workaround where I'm passing around my path parameters in the page model. 

#299002
Edited, Mar 26, 2023 16:58
Vote:
 

Have you tried to overriding/writing a custom implementation of the IUrlSegmentRouter interface?

#299039
Edited, Mar 27, 2023 7:34
Vote:
 

This is late but I would like adding a remark for later reference.

I think the updated UrlResolverContext' RouteValues should be available again for reading through a certain context-relatared service but currently have no idea how to do that.

As see, the HttpContext.Items is available through the pipeline from the IPartialRouter inheritance then to the Controller so we can use the HttpContext.Items property instead for passing desired values between the pipeline stages.

#306352
Edited, Aug 07, 2023 7:32
Praful - Jul 18, 2024 2:37
Thanks for sharing this information. I was stuck into the routing with the updated DotNet Core CMS 12 version. Because all the post I found are on older version and I couldn't find good code example with latest core version.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.