在mvc3中数据网格中的pagging [英] pagging in data grid in mvc3

查看:135
本文介绍了在mvc3中数据网格中的pagging的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我的mvc应用程序中有一个数据网格,我有分页。

我真正的问题是当我在第5页(或任何其他页面)并删除一个记录(行)然后它让我重定向到第一页而不是保持该页面本身。

i我试图获取记录被删除的页码但我是不成功的,

可以帮助我如何获取网格的页码或者其他一些方法来解决我的问题。

解决方案

那是因为,您没有将任何数据传递给您的删除方法,这可能使其能够重定向到相应的页面。以下示例给出了一个想法...



删除方法



  public  ActionResult Delete( int  itemId, int  pageNo)
{
// 使用itemId删除项目

// 通过传递页面号重定向到网格页面。太
return RedirectToAction( 索引 主页 {pageNumber = pageNo});
}





渲染删除链接时还包括生成的链接中的页码,即您的视图模型也应该包含当前页码。所以代替:



 http:// someurl / home / delete?itemId = 1 





生成:



 http:// someurl / home / delete?的itemId = 1&安培;您做生意= 5 


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.

解决方案

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


这篇关于在mvc3中数据网格中的pagging的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆