Try our conversational search powered by Generative AI!

Getting route data from partial route in a webform template

Vote:
 

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.

http://sdkbeta.episerver.com/SDK-html-Container/?path=/SdkDocuments/CMS/7/Knowledge%20Base/Developer%20Guide/Partial%20Routing/News%20partial%20routing%20example.htm&vppRoot=/SdkDocuments//CMS/7/Knowledge%20Base/Developer%20Guide/

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.

Adam

#70342
Apr 17, 2013 14:54
Vote:
 

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>();
#70345
Apr 17, 2013 15:09
Vote:
 

Thanks Johan, thats what I was looking for!

#70349
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.