Telerik Grid添加,更新和删除无效的事件

时间:2016-08-04 19:04:43

标签: asp.net-mvc telerik telerik-grid

直到我添加才识别出Telerik MVC网格列 @model IEnumerable<NTI.Data.EDC.LabUnit>作为我观点的第一行。但是当我添加这一行时。 Telerik MVC Grid加载数据并显示所有按钮。但插入,更新和删除事件未被触发。浏览器控制台窗口中没有Javascript错误。我还注意到telerik创建的插入/更新/删除按钮没有表单操作。请帮忙。

我的代码ref:http://www.telerik.com/help/aspnet-mvc/telerik-ui-components-grid-editing-ajax-editing.html

查看

@(
Html.Telerik().Grid(Model)
    .Name("Grid")
    .DataKeys(dataKeys => dataKeys.Add( c.ID))
    .ToolBar(commands => commands.Insert())
    .DataBinding(dataBinding => dataBinding
        //Ajax binding
        .Ajax()
        //Home.Index renders the grid initially
                .Select("LabUnits", "Lab")
        //Home.Insert inserts a new data record
                    .Insert("LabUnitsInsert", "Lab")
        //Home.Update updates an existing data record
                    .Update("LabUnitsUpdate", "Lab")
        //Home.Delete deletes an existing data record
                    .Delete("LabUnitsDelete", "Lab")
    )
    .Columns(columns =>
    {
        columns.Bound(c => c.ContactName);
        columns.Bound(c => c.Country);
        columns.Bound(c => c.BirthDay);
        columns.Command(commands => commands
               .Edit()
               .Delete());
    })

)

控制器

public class LabController : Controller
{
    public ActionResult LabUnits()
    {
        IEnumerable<LabUnit> lbUnit = new LabUnitDB().SelectAll();

        return View(new GridModel(lbUnit));
    }

    [HttpPost]
    [GridAction]
    public ActionResult LabUnitsInsert()
    {
        //insert
    }

    [HttpPost]
    [GridAction]
    public ActionResult LabUnitsUpdate(int id)
    {
        //update
    }

    [HttpPost]
    [GridAction]
    public ActionResult LabUnitsDelete(string id){
        // Delete
    }
}

1 个答案:

答案 0 :(得分:0)

我能够解决这个问题。不得不替换

comment.id

.DataBinding(dataBinding => dataBinding
        //Ajax binding
        .Ajax()

所以它的服务器绑定而不是Ajax。