Submit form with Kendo MVC Grid and other elements

前端 未结 3 1938
死守一世寂寞
死守一世寂寞 2020-12-29 09:42

I am trying to get a form containing a Kendo MVC grid and other elements to submit.

  • The View model contains contains three string fields and an IEnumer
3条回答
  •  天命终不由人
    2020-12-29 10:15

    I was inspired by codebeastie and @user1878526 to produce the following hybrid idea - simply returning the grid as a list of strings to the controller save action:

    Controller:

    Function Save(ThisForum As myModel, gridData As List(Of String)) As ActionResult
    

    View:

    $("#myForm").submit(function (event) {
        var grid = $("#myGrid").data("kendoGrid");
        var data = grid.dataSource.view();
        var input;
        for (var i = 0; i < data.length; i++) {
            var s = JSON.stringify(data[i]).replace(/["']/g, "");
            input = $("", { type: 'hidden', name: 'data[' + i + ']', value: s });
            $(this).append($(input));
        }
    })
    

    This can then be parsed in the controller reasonably easily by Spliting on commas and colons.

提交回复
热议问题