将不同的模型传递给模板以与Kendo Grid一起使用

时间:2015-03-18 20:55:09

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

是否可以使用Kendo Grid,其中从edit命令编辑的模型,甚至是自定义命令,与网格中列出的模型不同?

基本上我需要让网格显示一种类型的ViewModel列表,其中包含客户ID和电子邮件地址。当用户单击编辑按钮时,表单将允许他们批量添加/删除他们单击编辑的行的客户ID的电子邮件。

每次我尝试做这样的事情时,弹出窗口都会抛出错误的模型类型。

1 个答案:

答案 0 :(得分:0)

我不是100%肯定你想做什么。您说您的ViewModel具有ID和电子邮件地址,但您想批量添加电子邮件地址。我假设有多封电子邮件,但不管怎样,我的答案应该回答任何自定义编辑方案。

你必须自己处理它。剑道没有任何开箱即用的东西。

我开始做的是:

  • 将自定义命令添加为模板
  • 在按钮和类中添加模型的ID以查找此按钮<button class="custom-edit" data-targetid="#=Id#">Custom Edit</button>
  • 点击该按钮时打开一个窗口(我个人更喜欢一些标准的jQuery $.on()来收听此事件)

myGrid.element.on("click", ".custom-edit", function(ev){
    ev.preventDefault(); // In case your grid is in a form
    // Personally I just call an action that returns me a partial view with the ID as parameter and turn it into a window. You then bind to the window's close event to refresh the grid and destroy the window (unless you want to use the same window and just reload it)
});