5

I have a requirement which needs me to redirect an user to previous page on his browsing history. I am using ASP.net MVC 1.0. I do NOT want to use javascript to achieve this. Any pointers?

3 Answers 3

5

You can use the Request.UrlReferrer property to render out a link. Maybe like this:

<a href="<%= Request.UrlReferrer %>">Back</a>
Sign up to request clarification or add additional context in comments.

3 Comments

This will not work if the browser blocks the referrer... and many people seem to do that nowadays!
I've never had that problem to be honest - i guess the OP will have to decide whether this is a risk for his site though
It's fairly common to block the referrer when you are behind a corporate firewall.
0

You can take a parameter "returnUrl" in your action, and then return a RedirectResult. It should do.

For info, take a look at the Account controller, from the default template ASP.NET MVC project on VS2008.

Comments

0

And what about:

<a class="ImageBtn" href="previous.html" onClick="history.back();return false;">Go back</a>

In this case you can asign an image so it looks better.

2 Comments

That is using javascript ... and adding an image will increase the page load ... better to implement prettiness using CSS.
in fact the idea is to use css in the "class" also did not notice the "NOT"

Your Answer

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.