0

Is there a way to change the control of an Action and pass it to another Action without changing the URL?

public virtual ActionResult Mobile(bool redirectToPc = false)
{
    if (redirectToPc)
        return RedirectToAction("Home", "PC");

    return View();
}

I want to stay in the URL www.company.com/Mobile even if I am redirected to Action PC.

Patrick
  • 2,995
  • 14
  • 64
  • 125
  • possible duplicate of [RedirectToAction to different controller without changing URL](http://stackoverflow.com/questions/19145339/redirecttoaction-to-different-controller-without-changing-url) – Murilo Sep 08 '15 at 13:45

1 Answers1

0

A possibility is to make use of URL Rewriting, have a look at Scott Gu's blogpost Tip/Trick: Url Rewriting with ASP.NET. The idea is to perform the redirection while manipulating the URI to pretend you remained on the same page.

Example:

if (fullOrigionalpath.Contains("/Products/Books.aspx")) {
    Context.RewritePath("/Products.aspx?Category=Books");
}

But please don't do it yourself, look the part about UrlRewriter.net and UrlRewriting.net carefully.

Timothée Bourguignon
  • 2,190
  • 3
  • 23
  • 39