【问题标题】:Kendo UI Grid inline-edit posted data is nullKendo UI Grid 内联编辑发布的数据为空
【发布时间】:2012-12-04 07:04:03
【问题描述】:

我正在关注 MVC4 中的演示网格内联编辑,但我发现插入/编辑控制器中发布的网格数据为空。

cshtml代码如下:

@(Html.Kendo().Grid<CRM.Models.M_ProductGroup>()
    .Name("Group")
    .Columns(columns =>
    {
        //columns.Bound(g => g.CompanyNo).Hidden();
        columns.Bound(g => g.CompanyNo).Width(60);
        columns.Bound(g => g.ProductGroupNo).Width(60);
        columns.Bound(g => g.ProductGroupName).Width(120);
        columns.Command(command =>
        {
            command.Custom("SelectProducts");
            command.Edit();
            command.Destroy();
        }).Width(200);
    })
    .ToolBar(toolbar => toolbar.Create())
    .Editable(editable => editable.Mode(GridEditMode.InLine))
    .ClientDetailTemplateId("groupSetTemplate")
    .Pageable()
    .Sortable()
    .Scrollable()
    //.Resizable(resize => resize.Columns(true))
    .DataSource(dataSource => dataSource
        .Ajax()
        .Events(events => events.Error("error_handler"))
        .Model(model =>
        {
            model.Id(g => g.CompanyNo);
            model.Id(g => g.ProductGroupNo);
            //model.Field(g => g.ProductGroupName);
        })
        .Create(create => create.Action("InsertGroup", "MProductGroup"))
        .Read(read => read.Action("ShowGroup", "MProductGroup"))
        .Update(update => update.Action("ChangeGroup", "MProductGroup"))
        .Destroy(destroy => destroy.Action("DeleteGroup", "MProductGroup"))
    //.PageSize(20)
    )
    //.Events(events => events.DataBound("dataBound"))

控制器代码如下:

    [AcceptVerbs(HttpVerbs.Post)]
    public ActionResult InsertGroup([DataSourceRequest] DataSourceRequest request, M_ProductGroup group)
    {
        if (group != null && ModelState.IsValid)
        {
        return Json(new[] { group }.ToDataSourceResult(request, ModelState));
    }

    [AcceptVerbs(HttpVerbs.Post)]
    public ActionResult ChangeGroup([DataSourceRequest] DataSourceRequest request, M_ProductGroup group)
    {
        if (group != null && ModelState.IsValid)
        {

        }

        return Json(ModelState.ToDataSourceResult());
    }

发布的数据(“组”)为空,我无法获取。

【问题讨论】:

    标签: grid kendo-ui postdata


    【解决方案1】:

    检查您的项目中是否包含 kendo.aspnetmvc.min.js。

    【讨论】:

    • 非常感谢您的回答。它包含在我的项目中,例如:..\Scripts\kendo\2012.3.1114\kendo.aspnetmvc.min.js
    • 这很奇怪。您可以查看发布的数据是什么(使用浏览器的开发者工具)。
    • 我发现了新的东西:如果我将“group”更改为“productGroup”,例如 [AcceptVerbs(HttpVerbs.Post)] public ActionResult ChangeGroup([DataSourceRequest] DataSourceRequest request, M_ProductGroup productGroup),我可以发布数据;如果使用“组”,仍然无法获取发布的数据。为什么???
    • 不知道。可能是一些 ASP.NET MVC 模型绑定器怪癖。
    【解决方案2】:

    我有同样的问题,我发现了一件有趣的事情。

    代替

    [AcceptVerbs(HttpVerbs.Post)]
    public ActionResult ChangeGroup([DataSourceRequest] DataSourceRequest request, M_ProductGroup group)
    

    我做到了:

    [AcceptVerbs(HttpVerbs.Post)]
    public ActionResult ChangeGroup([DataSourceRequest] DataSourceRequest request, int ProductGroupNo, string ProductGroupName)
    

    我收到了我在内联网格中更改的 ID 和名称。

    我知道这是一个不雅的解决方案,而且是一件古董,但也许它会帮助您获得解决方案。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-09-02
      • 1970-01-01
      • 2016-01-01
      • 1970-01-01
      相关资源
      最近更新 更多