弹出如何在KendoUI网格中工作以及如何在MVC4的KendoUI ajax网格中弹出控件

时间:2013-02-02 11:18:12

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

单击编辑按钮时弹出窗口的工作原理以及如何在弹出窗口中显示三个Combobox。我真的对以下代码感到困惑

Client side Code

    //show server errors if any
    function error_handler(e) {
        if (e.errors) {
            var message = "Errors:\n\n";
            $.each(e.errors, function (key, value) {
                if ('errors' in value) {
                    $.each(value.errors, function () {
                        message += this + "\n\n";
                    });
                }
            });
            alert(message);
        }
    }


@(Html.Kendo().Grid(Model)
    .Name("SchoolGrid")
    .Columns(columns =>
    {
        columns.Bound(p => p.SchoolID).Width("80px");
        columns.Bound(p => p.Name);
        columns.Bound(p => p.Campus).Width("90px");
        columns.Bound(p => p.StateCode).Width("90px");
        columns.Bound(p => p.SectorCode).Width("95px");
        columns.Bound(p => p.MDISurveyStartDate).ClientTemplate("#= (MDISurveyStartDate == null) ? 'Not Set' : kendo.toString(MDISurveyStartDate, 'dd/MM/yyyy') #").Width("90px");
        columns.Bound(p => p.MDISurveyEndDate).ClientTemplate("#= (MDISurveyEndDate == null) ? 'Not Set' : kendo.toString(MDISurveyEndDate, 'dd/MM/yyyy') #").Width("90px");
        columns.Command(command => { command.Edit(); command.Destroy(); }).Width("190px").HtmlAttributes(new { style = "text-align:center" });
    })
    .ToolBar(tb => tb.Create().Text("Add New School"))
    .Editable(ed => ed.Mode(GridEditMode.PopUp).TemplateName("EditSchool").Window(w => w.Title("Add/Edit School Details").Name("editWindow").Width(600)))
    .DataSource(dataSource => dataSource
        .Ajax()
        .Model(model => model.Id(p => p.ClientID))
        .Events(e => e.Error("error_handler"))
        .Read("Read_Schools", "School")
        .Update("Update", "School")
        .Create("Create", "School")
        .Destroy("Destroy", "School")
    )
)


Server Side Code:-

        [HttpPost]
        public ActionResult Update([DataSourceRequest] DataSourceRequest request, School school)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    string errMsg = "";
                    if (!_Service.UpdateSchool(school, out errMsg))
                        ModelState.AddModelError("UpdateSchool", errMsg);
                }
            }
            catch (Exception ex)
            {
                ModelState.AddModelError("UpdateSchool", ex.Message);
            }

            return Json(ModelState.ToDataSourceResult());
        }

1 个答案:

答案 0 :(得分:0)

There is code library显示了如何操作Window的内容。其余的编辑可以通过Grid的编辑事件(检查文档)。