How to Keep current state while using PRG pattern?

140 Views Asked by At

I'm using PRG Pattern for HTTP Post in MVC. While I read about this I got some positive feedback on this method. And I felt this is the best approach.

Here is the reference: Post-Redirect-Get article on Andre Loker blog.

But when I use this, there is a disadvantage I've came across:

I've pagination in my page. When I am in 5th page - if I post any data, then it'll be redirected by PRG. So It goes to 1st page. I want to stay on the same 5th page.

So my question is: how to preserve opened page after posting a request?

2

There are 2 best solutions below

0
On BEST ANSWER

Instead of

return RedirectToAction("Action","Controller")

Use like the following

return Redirect(Url.Action("Action","Controller") + Request.Url.Query);
0
On

To stay on the same page, you have to send along the page number when you post the data, so that the server code can use that to redirect to an URL that shows that page.