【问题标题】:Kendo grid Custom Commands or etc to edit table data and perform action剑道网格自定义命令等来编辑表格数据并执行操作
【发布时间】:2013-06-04 15:12:55
【问题描述】:

我想更改记录的 int 状态并根据该更改发送一封电子邮件,所有这些都无需重定向到让用户更改状态的新页面。

我尝试将列模板按钮绑定到 JsonResult 操作的 href,但当然会重定向。

从外观上看,自定义命令是我最好的选择,但我希望尽可能多地利用现有的代码,除了电子邮件之外,一旦表格编辑成功运行,这部分就很容易了.

状态 = 待处理/批准/拒绝

Pending 是默认设置,因此在网格上只有 Approve 和 Decline 显示为状态更改选项。

查看代码:-

{
    field: 'Application',
    template: '<a style=\'width: 80px\' class=\'btn btn-success btn-block\' href=\' + sitePath + 'Placement/_Approve?Id=#=Id#\'>Approve</button>',
    width: 50
},
{
    template: '<a style=\'width: 80px\' class=\'btn btn-warning btn-block\' href=\' + sitePath + 'Placement/_Decline?Id=#=Id#\'>Approve</button>',
    width: 50
}

控制器动作

[HttpPost]
    public JsonResult _Approve(int Id)
    {
        SBApplication sba = _db.SBApplications.Find(Id);
        sba.PendingApprovedDeclined = 1;
        Placement pl = _db.Placements.Find(sba.PlacementId);
        if (pl.ApprovedCount == pl.PlacementSlots)
        {
            Session.Add("redirectedapprovelimit", "yes");
            return Json(View(new { @Id = sba.PlacementId }));
        }
        int i = pl.ApprovedCount;
        i++;
        pl.ApprovedCount = i;
        if (pl.PlacementSlots == pl.ApprovedCount)
        {
            pl.OpenClosedStatus = false;
        }
        if (ModelState.IsValid)
        {
            _db.Entry(pl).State = EntityState.Modified;
            _db.Entry(sba).State = EntityState.Modified;
            _db.SaveChanges();
        //// Insert email to student stating that there application is approved
        }
        return Json(View(new { @Id = sba.PlacementId }), JsonRequestBehavior.AllowGet);
    }

【问题讨论】:

  • 如果我不需要,我宁愿不用自定义命令,但它是我能找到的描述我正在尝试做的事情的封闭式。

标签: asp.net-mvc-4 kendo-ui kendo-grid


【解决方案1】:

默认情况下,超链接导航到在其href 属性中指定的 URL。除非被阻止,否则这会导致整页刷新。我可以建议使用 onclick 事件,并向所需的操作方法发出 ajax 请求。下面是一些示例代码:

模板定义

template: '<a onclick="return makeRequest(this)" href="' + sitePath + 'Placement/_Approve?Id=#=Id#">Approve</button>',

Ajax请求实现(放在网格定义之后)

<script>
function makeRequest(link) {
  // make an ajax request to the URL of the link (your action method)
  $.ajax({ 
    url: link.href 
  });
  return false; // prevent the link from navigating
}
</script>

【讨论】:

  • 谢谢,等我有时间再试一试,看看效果如何。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多