使用mvc重定向到页面

时间:2013-08-12 17:40:10

标签: c# asp.net-mvc

我在dll中包含了下面的第一个方法。我决定延长它                 这样我就可以控制重定向到哪个页面。此刻的时候                 我传递一个returnUrl没有任何反应。页面只返回到视图                 在哪里我输入了值。

?我希望能够重定向到位于此路径/ Views / Rental / Index中的页面                 我怎样才能做到这一点?

            [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);            

                    }

2 个答案:

答案 0 :(得分:0)

您可以使用ASP.NET MVC约定。:

RedirectResult("http://www.google.com");

答案 1 :(得分:0)

怎么样:

return RedirectToAction("Index", "Rental");