kusanagi
kusanagi

Reputation: 14614

create manually parameter ReturnUrl

i have view like 'home/details/5', it can be access by anonymous user. but there is button, which can be pressed only by registered users. no problem, i can look into Request.IsAuthenticated , and if anonymous i show button login instead of secret button

but the problem- when press login i can lose address and parameters of page. how can i create login button and pass a parameter ReturnUrl ? something like

 <%= Html.ActionLink("enter to buy", "LogOn", "Account", new { ReturnUrl = path to view with route value })%>

i see only stupid solution

<%= Html.ActionLink("enter to buy", "LogOn", "Account", new { ReturnUrl = "home/details/" + ViewContext.RouteData.Values["id"] })%>

but i don't like to hard code names of controller

Upvotes: 2

Views: 3390

Answers (1)

&#199;ağdaş Tekin
&#199;ağdaş Tekin

Reputation: 16651

You can also use Request.Url.AbsolutePath.

<%= Html.ActionLink("enter to buy", "LogOn", "Account", 
    new { ReturnUrl = Request.Url.AbsolutePath })%>

Upvotes: 5

Related Questions