redirect to return url after login

后端 未结 4 687
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-05 17:12

I have a link in my razor view like this:

  disputes

Inside my login\'s act

4条回答
  •  情书的邮戳
    2020-12-05 18:18

    If the ReturnURL is null, make sure you are calling the action method from the view as follows:

    // FormMethod.post is optional
    @using (Html.BeginForm("Login", "Account", new { ReturnUrl = ViewBag.ReturnUrl }, FormMethod.Post))
    {
        // login view html
    }
    

    Account controller:

    [AllowAnonymous]
    public ActionResult Login(string returnUrl)
    {
        ViewBag.ReturnUrl = returnUrl;
        return View();
    }
    

提交回复
热议问题