Try our conversational search powered by Generative AI!

Getting route data from partial route in a webform template


I have configured a partial route in a website which is using web form templates.

I have followed the tutorial on partial routing and am able to register a partial route which correctly loads my aspx template when the route is matched.

I dont know the best way to access the custom route data from within the web form template.

Following the example in the SDK, if I where to create a webforms template to display a "NewsContent" item, the code behind I would look like this.

public partial class NewsContentTemplate : EPiServer.SimplePage, IRenderTemplate<NewsContent>
	protected void Page_Load(object sender, EventArgs e)
		// This is how i am getting the route data
		var data = ((NewsContent)Request.RequestContext.RouteData.DataTokens["routedData"]);

    The code for accessing the route data works but is this correct / the best way? If this was a page, I would inherit TemplatePage<T> which gives typed access to the model, however I cannot do that here as NewsContent is not a page in the CMS.


Apr 17, 2013 14:54

You should be able to get the routed data through extension method to RequestContext that resides in namespace EPiServer.Web.Routing:

        var newsContent = Request.RequestContext.GetRoutedData<NewsContent>();
Apr 17, 2013 15:09

Thanks Johan, thats what I was looking for!

Apr 17, 2013 16:36
This thread is locked and should be used for reference only. Please use the Episerver CMS 7 and earlier versions forum to open new discussions.
* 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.