返回ASP.Net Core MVC中的上一页

时间:2021-07-05 04:04:11

From my client detail page I have a button to edit the client record which redirects to an edit page. I have a "return to client detail" link on the edit page which I want to redirect the user back to the previous client detail page.

从我的客户端详细信息页面,我有一个按钮来编辑重定向到编辑页面的客户端记录。我在编辑页面上有一个“返回客户端详细信息”链接,我想将用户重定向回以前的客户端详细信息页面。

<a asp-controller="Client" asp-action="Detail" asp-route-id="@Model.ClientID">Return to client detail</a>

Currently this works as expected but takes extra time as it reloads the detail page from scratch (ie running all the various db queries again). Since the user is really just cancelling the edit without any changes to the state of the client I am wanting to return the user to the previous detail page without having to go through the controller action again.

目前,这可以按预期工作,但从头开始重新加载详细信息页面(即再次运行所有各种数据库查询)需要额外的时间。由于用户实际上只是在不更改客户端状态的情况下取消编辑,因此我希望将用户返回到上一个详细信息页面,而无需再次执行控制器操作。

Essentially I am wanting to simulate the browser back button (to improve responsiveness) but i'm not sure how to implement this or whether it's good practice to do so. Some guidance would be appreciated.

基本上我想模拟浏览器后退按钮(以提高响应能力),但我不知道如何实现这一点或是否这样做是好的做法。一些指导意见将不胜感激。

Thanks

4 个解决方案

#1


7  

You can use

您可以使用

<a href='javascript:history.go(-1)'>Return to client detail</a>

or onclick

<a href="##" onClick="history.go(-1); return false;"> Return to client detail</a> 

#2


6  

U know what? I hate JS so i will write answer with backend side. The HTTP referer is an HTTP header field that identifies the address of the webpage that linked to the resource being requested. So simply read that and pass to view (always remember about XSS and validation, user can easly spoof HTTP request)

你知道吗?我讨厌JS,所以我会用后端方面写回答。 HTTP referer是一个HTTP头字段,用于标识链接到所请求资源的网页的地址。所以只需阅读并传递给视图(永远记住XSS和验证,用户可以轻松欺骗HTTP请求)

In action controller

在行动控制器

if(Request.Headers["Referer"] != null)
{
    ViewData["Reffer"] = Request.Headers["Referer"].ToString();
}

In view (razor)

在视野中(剃刀)

@if(!string.IsNullOrWhiteSpace(ViewData["Reffer"]))
{
    <a href="@ViewData["Reffer"]">Return to client detail</a>
}

#3


0  

It should be like this

它应该是这样的

<input type="button" onclick= "history.go(-1)" value="Return to client detail" />

#4


0  

I think that you need to get rid of the idea of passing through the controller. If you need to browse quickliest with asp net core code about href you can try this.

我认为你需要摆脱通过控制器的想法。如果您需要使用关于href的asp net核心代码快速浏览,可以试试这个。

 <a asp-area="" onclick="history.go(-1);">Return to client detail</a>

#1


7  

You can use

您可以使用

<a href='javascript:history.go(-1)'>Return to client detail</a>

or onclick

<a href="##" onClick="history.go(-1); return false;"> Return to client detail</a> 

#2


6  

U know what? I hate JS so i will write answer with backend side. The HTTP referer is an HTTP header field that identifies the address of the webpage that linked to the resource being requested. So simply read that and pass to view (always remember about XSS and validation, user can easly spoof HTTP request)

你知道吗?我讨厌JS,所以我会用后端方面写回答。 HTTP referer是一个HTTP头字段,用于标识链接到所请求资源的网页的地址。所以只需阅读并传递给视图(永远记住XSS和验证,用户可以轻松欺骗HTTP请求)

In action controller

在行动控制器

if(Request.Headers["Referer"] != null)
{
    ViewData["Reffer"] = Request.Headers["Referer"].ToString();
}

In view (razor)

在视野中(剃刀)

@if(!string.IsNullOrWhiteSpace(ViewData["Reffer"]))
{
    <a href="@ViewData["Reffer"]">Return to client detail</a>
}

#3


0  

It should be like this

它应该是这样的

<input type="button" onclick= "history.go(-1)" value="Return to client detail" />

#4


0  

I think that you need to get rid of the idea of passing through the controller. If you need to browse quickliest with asp net core code about href you can try this.

我认为你需要摆脱通过控制器的想法。如果您需要使用关于href的asp net核心代码快速浏览,可以试试这个。

 <a asp-area="" onclick="history.go(-1);">Return to client detail</a>