Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Partial Routing in EPiServer dealing with extra Route data.
public class NewsListPartialRouting : IPartialRouter<NewsListPage, NewsListPage>
{
public object RoutePartial(NewsListPage content, SegmentContext segmentContext)
{
var nextSegment = segmentContext.GetNextValue(segmentContext.RemainingPath);
var urlSegment = nextSegment.Next;
if (string.IsNullOrEmpty(urlSegment))
{
return null;
}
segmentContext.RemainingPath = nextSegment.Remaining;
segmentContext.RoutedContentLink = content.ContentLink;
int page;
if(!int.TryParse(urlSegment, out page))
{
return content;
}
segmentContext.RouteData.Values["page"] = page;
return content;
}
public PartialRouteData GetPartialVirtualPath(NewsListPage content, string language, RouteValueDictionary routeValues,
RequestContext requestContext)
{
var contentLink = ContentRoute.GetValue("node", requestContext, routeValues)
as ContentReference;
if (!content.ContentLink.CompareToIgnoreWorkID(contentLink))
{
return null;
}
if (PageEditing.PageIsInEditMode)
{
return null;
}
return new PartialRouteData
{
BasePathRoot = content.ContentLink,
PartialVirtualPath = content.URLSegment
};
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment