문제

I'm building an app and on my Checkout controller I have the [Authorize] attribute. I want my users to be logged in before they checkout any orders.

However on this method:

[HttpGet]
[AllowAnonymous]
public ActionResult Login(string _returnUrl)
{
    ViewBag.ReturnUrl = _returnUrl;

    return View();
}

The _returnUrl string is always empty. How can I provide the parameter with the current url browsed by the user?

도움이 되었습니까?

해결책

You need to match the query string parameter names in the Control Action methods so that model binder can pass them in correctly. So in you case it should be string retrunUrl not string _returnUrl.

...
public ActionResult Login(string returnUrl)
{
    ViewBag.ReturnUrl = returnUrl;
    return View();
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top