jqGrid添加行无效

时间:2012-05-05 21:08:58

标签: jqgrid

获取,编辑和删除所有工作正常。但是add不会调用我的ActionResult方法。我正在使用内联添加,显示新记录值的模态表单。似乎很少有关于如何使用最新jqGrid版本中提供的pager / form方法的示例。在这里添加/插入我缺少什么?

HTML:

            $("#grid").jqGrid({
                url: 'ABC.Admin/CourseAdmin/GetLocationData/',
                datatype: 'json',
                jsonReader: { repeatitems: false },
                mtype: 'GET',
                colNames: ['Location Id', 'Name', 'Address Line 1'],
                colModel: [
              { name: 'LocationId', index: 'LocationId', width: 40, key: true },
              { name: 'LocationName', index: 'LocationName', width: 150, editable: true },
              { name: 'AddressLine1', index: 'AddressLine1', width: 150, editable: true },
              ],
                pager: jQuery('#pager'),
                rowNum: 20,
                sortname: 'Name',
                sortorder: "asc",
                viewrecords: true,
                caption: '***Testing***',
                height: 200,
                loadonce: true, // needs to be true for client side paging to work
                autowidth: true,
                loadtext: 'Loading...'
            })
            $("#grid").jqGrid('navGrid', '#pager', { edit: true, add: true, del: true },
            { // edit options 
                url: 'ABC.Admin/CourseAdmin/SaveLocation/',
                closeAfterEdit: true
            },
            { // add
                url: 'ABC.Admin/CourseAdmin/Create/'
            },
            { //delete
                url: 'ABC.Admin/CourseAdmin/DeleteLocation/',
                closeOnEscape: true
            }
        );

控制器:

public ActionResult Create(int id,string locationName,string addressLine1)

[HttpPost]
public ActionResult CreateLocation(string oper, string id, string locationName, string addressLine1)        {
            //Models.LocationProvider lp = new Models.LocationProvider();
            //bool saved = lp.InsertLocation(location);
            bool saved = false;
            if (!saved)
            {
                Response.StatusCode = 500;
                return Content("Record not saved!");
            }
            else
            {
                return Json(false);
            }
        }

1 个答案:

答案 0 :(得分:0)

我弄清楚了。 Create方法sig中参数的类型不匹配。他们需要成为所有字符串。将我的控制器更改为以下工作。我还注意到 id oper 参数是通过名称而不是订单来获取的 - 所以我可以将它们放在签名中的第一个或最后一个(或任何地方)它们得到正确的价值 - 很酷!我将使用此更正编辑我的原始帖子。

        public ActionResult Create(string oper, string id, string locationName, string addressLine1)

对于其他寻找jqGrid添加/插入示例的人,我希望这个有用。