Reputation: 14520
Here is my actionlink to my login page with route values as null, so now my controllers Login action gets a returnUrl value of null
<li>@Html.ActionLink("Log in", "Login", "Account", routeValues: null, htmlAttributes: new { id = "loginLink" })</li>
If I'm on my search page where the URL has parameters like this
www.mypage.com/home/search&city=san+francisco&ClassDate=08%2F25%2F2015
and then I click on the login link what gets put into the route values so that I can get back to this page with these parameters? Will the page reload when I go back after I login?
Here is the controller action.
[AllowAnonymous]
public ActionResult Login(string returnUrl)
{
ViewBag.ReturnUrl = returnUrl;
return View();
}
Upvotes: 0
Views: 775
Reputation: 2316
Quick and dirty option:
@Html.ActionLink("Log in", "Login", "Account", new { returnUrl = Request.RawUrl }, new { id = "loginLink" })
Best practice though, would be to add the ReturnUrl
to a model, and pass that to the view:
@Html.ActionLink("Log in", "Login", "Account", new { returnUrl = Model.ReturnUrl }, new { id = "loginLink" })
Upvotes: 1