Return to previous page in ASP.Net Core MVC
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>
For IActionResult
you can use this code:
public IActionResult Test()
{
return Redirect(Request.Headers["Referer"].ToString());
}
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)
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>
}