Currently in a link
Customer/businessunit/RepresentativeDetails?RepresentativeId=cd3a7263-78f7-41bd-9eb0-12b30bc1059a
I have following code for view
@Html.ActionLink("Back to List", "Index")
which takes me to this link
customer/businessunit/index
but rather that going to index page I want to go to previous page when the actionlink is clicked, which is
Customer/businessunit/BusinessUnitDetails/c4a86253-a287-441e-b83d-71fbb6a588bc
How do I create an actionlink that directs me to previous page? something like @Html.ActionLink("Back to Details", //go to previous page)
ActionLink(HtmlHelper, String, String) Returns an anchor element (a element) for the specified link text and action. ActionLink(HtmlHelper, String, String, Object) Returns an anchor element (a element) for the specified link text, action, and route values.
Yes, there is a difference. Html. ActionLink generates an <a href=".."></a> tag whereas Url. Action returns only an url.
If you need to pass through the reference to an object that is stored on the server, then try setting a parameter of the link to give a reference to the object stored on the server, that can then be retrieved by the action (example, the Id of the menuItem in question).
ActionLink is rendered as an HTML Anchor Tag (HyperLink) and hence it produces a GET request to the Controller's Action method which cannot be used to submit (post) Form in ASP.Net MVC 5 Razor. Hence in order to submit (post) Form using @Html. ActionLink, a jQuery Click event handler is assigned and when the @Html.
Unless you're tracking what the previous page is on the server, why not just use the browser's internal history? In that case there wouldn't be a need for server-side code. You could just use something like this:
<a href="javascript:void(0);" onclick="history.go(-1);">Back to Details</a>
Or, separating the code from the markup:
<a href="javascript:void(0);" id="backLink">Back to Details</a> <script type="text/javascript"> $(document).on('click', '#backLink', function () { history.go(-1); }); </script>
This would send the user back to whatever was the last page in their browser history. (Of course, if they reached that page from any other source then it wouldn't take them "back to details" but instead just "back".)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With