Try our conversational search powered by Generative AI!

How to redirect to another page from MVC controller

Vote:
 

Hi,

 

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!

#71418
May 17, 2013 11:43
Vote:
 

Here is how we do it:

var pageReference = ???

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

var pageUrl = urlResolver.GetVirtualPath(pageReference);

Redirect(pageUrl);

    

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

Greetings

#71420
Edited, May 17, 2013 11:55
Vote:
 

Great thanks this did the trick!

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