Click here to Skip to main content
Rate this: bad
Please Sign up or sign in to vote.
See more: MVC DataGrid
Hello All,
I have a datagrid in my mvc application, i got paging to it.
my real problem is when i am on 5th page(or any other page) and delete a record(row) then its getting me redirect to 1st page instead of keeping on that page itself.
i am trying to get the page number from where the record is deleted but i am unsuccessful in that,
can any one help me how to get the page number of grid or some how from some other way to solve my problem.
Posted 28-Dec-12 18:26pm
salah9 at 31-Dec-12 0:35am
is it k nw???
sorry i m new to this blog..
Karthik. A at 31-Dec-12 0:43am
No worries! This is fine too, if you have comments about an answer you have to comment against that. You will get used to all these stuff as you get acquainted w/ CodeProject! Welcome by the way!!!
salah9 at 31-Dec-12 0:46am
thanks.. : )

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

That's because, you are not passing any data to your delete method that could enable it to redirect to the appropriate page. Following sample gives you an idea...
Delete method
public ActionResult Delete(int itemId, int pageNo)
   // delete the item using itemId

   // redirect to grid page by passing the page no. too
   return RedirectToAction("Index", "Home", new { pageNumber = pageNo });
While rendering the delete link also include the page number in the link generated, i.e., your view model should also contain the current page number. So instead of:
Abhishek Pant at 29-Dec-12 20:43pm
Karthik. A at 31-Dec-12 0:09am
Thanks !

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 476
1 Sergey Alexandrovich Kryukov 235
2 CHill60 195
3 Afzaal Ahmad Zeeshan 145
4 TheRealSteveJudge 120
0 Sergey Alexandrovich Kryukov 9,121
1 OriginalGriff 7,920
2 Peter Leow 4,774
3 Kornfeld Eliyahu Peter 3,210
4 Maciej Los 2,176

Advertise | Privacy | Mobile
Web03 | 2.8.150327.1 | Last Updated 30 Dec 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100