Our monthly Virtual Happy Hour is happening this week, Fri Feb 23!

Try our conversational search powered by Generative AI!

How to redirect to another page from MVC controller




just taking my baby steps in the world of MVC and EPi. What is correct way to redirect from controller to another page provided that I have the redirection target as PageReference/PageData?

I was looking at RedirectToRoute but couldn't yet figure out how to resolve route for page from PageReference/PageLink? 

Response.Redirect of course works but seemed to as not the most elegant solution? Or I am just making simple task too complicated?

Any advice appreciated!

May 17, 2013 11:43

Here is how we do it:

var pageReference = ???

var urlResolver = EPiServer.ServiceLocation.ServiceLocator.Current.GetInstance<EPiServer.Web.Routing.UrlResolver>();

var pageUrl = urlResolver.GetVirtualPath(pageReference);



Look here for more information: http://joelabrahamsson.com/episerver-7-and-mvc-getting-the-url-for-a-page/


Edited, May 17, 2013 11:55

Great thanks this did the trick!

May 17, 2013 13:06
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.