将所有jqgrid数据从视图传递到控制器

时间:2017-08-08 08:21:48

标签: c# asp.net-mvc jqgrid

如何将所有jqgrid数据从视图传递到控制器?

当我硬编码数据时,它会从视图传递给控制器​​。

当我删除硬编码数据并写入url时,数据不会从视图传递到控制器,列表显示 Null 值。

[HttpPost]
public ActionResult Airlines(List<Airlines> objAirlines)
{
        for (int i = 0; i < objAirlines.Count; i++)
        {
            cmd = new SqlCommand("SP_AirLine_FlightInsert");
            cmd.CommandType=CommandType.StoredProcedure;
            cmd.Parameters.AddWithValue("@ALCode", objAirlines[i].ALCode);
        }

        return View();
}

<script type="text/javascript">
$(function ()  {
         $("#grid1").jqGrid({
             url: '@Url.Action("SelectAirlines")',
             type: 'GET',
            datatype: 'json',
            jsonReader: { id: 'ALCode' },
            colModel: [
                    { name: 'ALName', width: 200 },

           { name: 'Details', width: '20', formatter: function (cellvalue, options, rowObject) {
               return returnUpdateLink(cellvalue, options, rowObject);
           }
           },

        ],
            cmTemplate: { autoResizable: true, editable: true },
            autoResizing: { compact: true },
            viewrecords: true,
            pager: true,
            height: 200,
            width: 800,
            rowNum: 10,
            iconSet: "fontAwesome",
            rownumbers: true,
            sortname: "invdate",
            sortorder: "desc",
            caption: "Airlines"
        }).jqGrid("navGrid")
            .jqGrid("inlineNav");

        $("#saveAll").click(function () {
            var data = [ ];
            var data = $("#grid1").jqGrid("getGridParam", "data");
            var dataToSend = JSON.stringify(data);
             $.ajax({
         url: '@Url.Action("Airlines")',
         type: 'POST',
         contentType: 'application/json; charset=utf-8',
         data: dataToSend,
         dataType: 'json',
         success: function (result) {
             alert('success: ' + result.result);
         }
     });
     return true;
</script>

0 个答案:

没有答案