There may be a time when you would want to return to the previously visited page when performing action on data.

One simple method is to use a helper or extension class. To maintain separation of concerns, create a helper or extensions folder where you would put your class. In my case I created a helper folder in the project root and created a file named RequestUrl.cs, with the following code in it.


Add the using statement in your controller


In the GET action, use TempData to get the URL.


And finally, in the POST action, enter this code.


When the POST action completes the app will redirect to the previous URL.