4

I'm following the demo grid inline-edit in MVC4, but I find the posted gird data in Insert/Edit Controller is null.

code of cshtml as follows:

@(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"))

code of controller as follows:

    [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());
    }

posted data ("group") is null, I can't get it.

user1905916
  • 41
  • 1
  • 2

2 Answers2

1

Check if you have kendo.aspnetmvc.min.js included in your project.

Atanas Korchev
  • 30,562
  • 8
  • 59
  • 93
  • Very thanks for your answer. It is included in my project like: ..\Scripts\kendo\2012.3.1114\kendo.aspnetmvc.min.js – user1905916 Dec 17 '12 at 09:05
  • That's odd. You can check what the posted data is (use the developer tools of your browser). – Atanas Korchev Dec 17 '12 at 09:25
  • 2
    I find new thing: if I change "group" to "productGroup" like [AcceptVerbs(HttpVerbs.Post)] public ActionResult ChangeGroup([DataSourceRequest] DataSourceRequest request, M_ProductGroup productGroup), I can get posted data; if use "group", still can't get posted data. why??? – user1905916 Dec 17 '12 at 09:41
  • No idea. Probably some ASP.NET MVC model binder quirk. – Atanas Korchev Dec 17 '12 at 09:55
1

I have the same problem, And I found an interesting thing.

Instead of

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

I did:

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

And i recived the Id and the name that i changed in the inline grid.

I know that is an inelegant solution, and a curios thing, but maybe it will serve you to get the solution.

Albert Cortada
  • 737
  • 3
  • 10
  • 25