1

获取、编辑和删除都可以正常工作。但是 add 不会调用我的 ActionResult 方法。我正在使用显示新记录值的模式表单的内联添加。似乎很少有例子说明这如何与最新 jqGrid 版本中提供的寻呼机/表单方法一起工作。我在这里添加/插入缺少什么?

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);
            }
        }
4

1 回答 1

0

我搞定了。Create 方法 sig 中的参数类型不匹配。它们必须是所有字符串。将我的控制器更改为以下作品。我还注意到idoper参数是按名称而不是顺序提取的 - 所以我可以将它们放在签名中的第一个或最后一个(或任何位置),它们会得到正确的值 - 太棒了!我将使用此更正编辑我的原始帖子。

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

对于其他正在寻找 jqGrid 添加/插入示例的人,我希望这个对您有所帮助。

于 2012-05-05T21:48:59.923 回答