1

I have the first method below contained in a dll. I decided to extend it so that I can have control over which page to redirect to. At the moment when I pass a returnUrl nothing happens. The page just returns to the view where I entered values.

? I want to be able to redirect to a page that resides in this path /Views/Rental/Index How can I achieve that?

            [HttpPost]   
                public virtual ActionResult CreateAccount(CreateNewAccountInfo createNewAccountInfo, WebSite webSite, string returnUrl)
                {
                  if (this._accountManager.UserNameAlreadyExists(createNewAccountInfo.UserName))
                    this.ModelState.AddModelError("CreateNewAccountInfo", ErrorMessageProvider.CreateNewAccountInfo_UserName_AlreadyExists);

                  if (this.ModelState.IsValid)
                  {
                    this._accountManager.CreateNewAccount(createNewAccountInfo);        
                    return this.RedirectToReturnUrl(returnUrl);
                  }
                  else
                  {
                    SignIn1ViewModel signIn1ViewModel = this.CreateSignIn1ViewModel(webSite, returnUrl);
                    this.SetupGuestCheckout(webSite, returnUrl, signIn1ViewModel);
                    return (ActionResult) this.View(signIn1ViewModel.WebPage.ViewName, (object) signIn1ViewModel);
                  }
                }


             public override ActionResult CreateAccount(CreateNewAccountInfo createNewAccountInfo, WebSite webSite, string returnUrl)
                    {
                        returnUrl = "../Views/Rental/Index";
                        base.CreateAccount(createNewAccountInfo,webSite,returnUrl);

                        return base.CreateAccount(createNewAccountInfo, webSite, returnUrl);            

                    }
tereško
  • 58,060
  • 25
  • 98
  • 150
Baba
  • 2,059
  • 8
  • 48
  • 81
  • Have you tried [.net mvc redirect to external url](http://stackoverflow.com/questions/1549324/net-mvc-redirect-to-external-url)? – Dustin Kingen Aug 12 '13 at 17:42
  • No I have not. How does that work? Please note that I am not able to modify the dll. Everything I need to do has to be done from where I am doing the override. – Baba Aug 12 '13 at 17:46

2 Answers2

0

You can use ASP.NET MVC conventions.:

RedirectResult("http://www.google.com");
Rahul Tripathi
  • 168,305
  • 31
  • 280
  • 331
  • Thanks. Where will this go in the method I am overriding? – Baba Aug 12 '13 at 17:47
  • Here return this.RedirectToReturnUrl(returnUrl); – Rahul Tripathi Aug 12 '13 at 17:48
  • My file resides here "../Views/Rental/Index" and I used this path return this.RedirectToReturnUrl("../Views/Rental/Index"); but still unable to get the page to display. Do you know what else i can try? – Baba Aug 12 '13 at 17:59
0

What about:

return RedirectToAction("Index", "Rental");
Mister Epic
  • 16,295
  • 13
  • 76
  • 147
  • Np. Remember, in MVC your URLs are now mapping to actions, not to pages so typically RedirecToAction will be your friend if you're doing an internal redirect. – Mister Epic Aug 12 '13 at 19:57