Click here to Skip to main content
Rate this: bad
good
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
salah91K
Comments
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
good
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:
 
http://someurl/home/delete?itemId=1
 
generate:
 
http://someurl/home/delete?itemId=1&pageNo=5
  Permalink  
Comments
Abhishek Pant at 29-Dec-12 20:43pm
   
+5
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 410
1 Jochen Arndt 200
2 Richard MacCutchan 135
3 DamithSL 105
4 PIEBALDconsult 90
0 OriginalGriff 6,045
1 DamithSL 4,601
2 Maciej Los 4,032
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,220


Advertise | Privacy | Mobile
Web02 | 2.8.141220.1 | Last Updated 30 Dec 2012
Copyright © CodeProject, 1999-2014
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