MVC-删除项目而不重新加载整个页面 [英] MVC - deleting items without reloading whole page

查看:167
本文介绍了MVC-删除项目而不重新加载整个页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我正在尝试查看是否有更好的方法可以解决此问题.我基本上是从jqGrid删除一个项目.现在,这显然可以适用于任何列表.但是,有没有一种方法可以删除条目并更新数据库而无需重新加载页面,而只是刷新网格?

 功能 onDeleteClient(){
     var  url = ' /Clients/Delete/'跨度>;
     var  clientId = jQuery(' #client_grid').jqGrid('  getGridParam'' span> 借');
    窗口.位置 .href = url +  parseInt (clientId);
    $(' #client_grid').trigger("  reloadGrid",[{页面: 公共 ActionResult Delete( int  id)
{
     var 模型=  ClientsModel();
    model.Delete(id);
    返回 RedirectToAction(" );
}



因此您可以看到控制器会将其重定向回原始页面并显示更新的结果.但是,有什么方法可以更新控制器并停留在原始页面上吗?然后,我可以刷新网格.

感谢任何指针...

解决方案

(' #client_grid').trigger(" ,[{页面: 1 }]); };



 公共 ActionResult Delete( int  id)
{
     var 模型=  ClientsModel();
    model.Delete(id);
    返回 RedirectToAction(" );
}



因此您可以看到控制器会将其重定向回原始页面并显示更新的结果.但是,有什么方法可以更新控制器并停留在原始页面上吗?然后,我可以刷新网格.

任何指针都值得赞赏...


RedirectToAction("Index");
这将导致整个页面刷新.
尝试将部分视图与Ajax get/post调用一起使用以进行部分页面刷新.


hi im trying to see if there is a better way to go about this. Im basically deleting an item from a jqGrid. Now this could obviously apply to any list. But is there a way to delete the entry and update the database without reloading the page, just refreshing the grid?

function onDeleteClient() {
    var url = '/Clients/Delete/';
    var clientId = jQuery('#client_grid').jqGrid('getGridParam', 'selrow');
    window.location.href = url + parseInt(clientId);
    $('#client_grid').trigger("reloadGrid", [{ page: 1}]);
};



public ActionResult Delete(int id)
{
    var model = new ClientsModel();
    model.Delete(id);
    return RedirectToAction("Index");
}



so as you can see the controller will redirect it back to the original page and show the updated results. But is there a way we can update the controller and stay on the original page? Then i can just refresh the grid.

any pointers are appreciated...

解决方案

('#client_grid').trigger("reloadGrid", [{ page: 1}]); };



public ActionResult Delete(int id)
{
    var model = new ClientsModel();
    model.Delete(id);
    return RedirectToAction("Index");
}



so as you can see the controller will redirect it back to the original page and show the updated results. But is there a way we can update the controller and stay on the original page? Then i can just refresh the grid.

any pointers are appreciated...


RedirectToAction("Index");
This will cause the entire page to refresh.
Try using partial views with an Ajax get/post call to do a partial page refresh.


这篇关于MVC-删除项目而不重新加载整个页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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