Click here to Skip to main content
15,891,431 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
Comments
salah9 31-Dec-12 0:35am    
is it k nw???
sorry i m new to this blog..
Karthik. A 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 31-Dec-12 0:46am    
thanks.. : )

1 solution

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

C#
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
 
Share this answer
 
Comments
Abhishek Pant 29-Dec-12 20:43pm    
+5
Karthik. A 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)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900