on html.actionlink click go to previous page

后端 未结 6 523
攒了一身酷
攒了一身酷 2021-01-31 16:17

Currently in a link

Customer/businessunit/RepresentativeDetails?RepresentativeId=cd3a7263-78f7-41bd-9eb0-12b30bc1059a

I have following code for vie

相关标签:
6条回答
  • 2021-01-31 16:33

    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".)

    0 讨论(0)
  • 2021-01-31 16:35

    Don't use ActionLink for this... just do:

    <a href="javascript:history.back()">Back to List</a>

    ...which will take the user back to wherever they were prior to the current page

    0 讨论(0)
  • 2021-01-31 16:38

    If you don't like to use ActionLink or JavaScript, the href="@Request.UrlReferrer" will do the trick:

    <div>
        <a href="@Request.UrlReferrer" class="btn btn-default btn-lg" title="Back to list">
            <span class="glyphicon glyphicon-arrow-left" aria-hidden="true"></span>
        </a>
    </div>
    
    0 讨论(0)
  • 2021-01-31 16:46

    If you still want to use ActionLink you can do something like as suggested by JuanPieterse

    @Html.ActionLink("Back to previous page", null, null, null, new { href = Request.UrlReferrer})
    

    You can use action in controller too. See answers to similar question here

    0 讨论(0)
  • 2021-01-31 16:55

    This is quite a bit after the fact, but I thought I'd contribute. Personally, I would tag my markup elements with a CSS class so I could just reuse the tag and be done with it.

    Markup:

    <a href="" class="go_back"> Back </a>
    

    Script:

    <script type="text/javascript">
        $(function () {
            $('.go_back').click(function (e) {
                e.preventDefault();
                history.go(-1);
            });
        });
    </script>
    
    0 讨论(0)
  • 2021-01-31 16:55

    Use ActionLink:

    @Html.ActionLink("بازگشت", null, null, null, new { href = Request.UrlReferrer })
    
    0 讨论(0)
提交回复
热议问题