2

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

asked Mar 17, 2010 at 2:10

1 Answer 1

5

You can also use Request.Url.AbsolutePath.

<%= Html.ActionLink("enter to buy", "LogOn", "Account", 
 new { ReturnUrl = Request.Url.AbsolutePath })%>
answered Mar 17, 2010 at 2:15
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.