在html.actionlink上,单击转到上一页 [英] on html.actionlink click go to previous page

查看:114
本文介绍了在html.actionlink上,单击转到上一页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当前在链接中

客户/业务部门/ RepresentativeDetails?RepresentativeId = cd3a7263-78f7-41bd-9eb0-12b30bc1059a

我有以下查看代码

@Html.ActionLink("Back to List", "Index")

需要我转到此链接

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

如何创建可以将我定向到上一页的actionlink?
类似于 @ Html.ActionLink(返回详细信息,//转到上一页)

How do I create an actionlink that directs me to previous page? something like @Html.ActionLink("Back to Details", //go to previous page)

推荐答案

除非您要跟踪服务器上的上一页,否则为什么不只使用浏览器的内部历史记录呢?那样的话,就不需要服务器端代码了。您可以使用类似这样的东西:

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

这篇关于在html.actionlink上,单击转到上一页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆