Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Return to previous page in ASP.Net Core MVC

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

like image 941
OjM Avatar asked Feb 14 '17 10:02

OjM


1 Answers

For IActionResult you can use this code:

public IActionResult Test()
{
    return Redirect(Request.Headers["Referer"].ToString());
}
like image 174
Diako Hasani Avatar answered Sep 22 '22 11:09

Diako Hasani