I am using ASP.NET MVC3 for my web application. To display a button in the User Interface I am using the following html in my View1.cshtml.
<div class="demo">
<input type="submit" value="Save" title="Click here to create a comment" />
<input type="button" value="Cancel" onclick="location.href='/'" title="Click here to cancel and go back to main menu" />
</div>
I want to place a button so that users can go back to the previous page.. So to achieve this I want to place a button in the .cshtml which takes View Name and can
- transfer to specific view. (or)
- To the previous view.
Any one above requirements will be good for my application.
How can I do this? Any help or ideas will be useful to me.
Thank you
If you want to send the user to their previous page, you can always use
Request.UrlReferrerin your controller, but beware that it’s possible for them to spoof this quite easily. Another way would be to store the previous location in the session for the user, then you could retrieve it and hook it up to the button in your view.As for wanting a button, take a look here: Html.ActionLink as a button or an image, not a link
Mind you, is it really necessary to add a back button? Most browsers have them built in 😉