【问题标题】:inline edit in jqgrid not workingjqgrid中的内联编辑不起作用
【发布时间】:2012-06-27 12:23:01
【问题描述】:

我有这样的 jQuery 代码

$(document).ready(function () {

         var lastsel;

    $('#jqgProducts').jqGrid({
             //url from wich data should be requested
             url: '@Url.Action("CompOff")',
         //type of data
         datatype: 'json',
         //url access method type

         mtype: 'POST',
         //columns names

         ondblClickRow: function (id) {
             if (id && id !== lastsel) {
                 jQuery('#list').restoreRow(lastsel);
                 jQuery('#list').editRow(id, true);
                 lastsel = id;
             }
             $('#jqgProducts').editRow(id, true,null, null);
         },

         editurl: '@Url.Action("CompOffEdit")',
         colNames: ['IdNr', 'CompOffDate', 'Description', 'ExpiryDate', 'IsApproved', 'AppliedOn'],
         //columns model
         colModel: [
                    { name: 'Id', index: 'Id', align: 'center', editable: true, hidden: true},
                        { name: 'CompOffDate', index: 'CompOffDate', align: 'center', formatter: 'date', formatoptions: { newformat: 'd/m/Y' }, editable: true },
                          { name: 'Description', index: 'Description', align: 'center', editable: true, editoptions: { maxlength: 200} },
                        { name: 'ExpiryDate', index: 'ExpiryDate', align: 'center', formatter: 'date', formatoptions: { newformat: 'd/m/Y' }, editable: false },
                        { name: 'IsApproved', index: 'IsApproved', align: 'center', editable: false },

                        { name: 'AppliedOn', index: 'AppliedOn', align: 'center', formatter: 'date', formatoptions: { newformat: 'd/m/Y' }, editable: false }

                      ],
         //pager for grid
         pager: $('#jqgpProducts'),
         //number of rows per page
         rowNum: 10,
         //initial sorting column
         sortname: 'CompOffDate',
         //initial sorting direction
         sortorder: 'asc',
         //we want to display total records count
         viewrecords: true,

         caption: 'Comp Off Details',
         //grid height
         height: '100%',

         jsonReader: {
             root: "rows",
             page: "page",
             total: "total",
             records: "records",
             repeatitems: false,
             cell: "cell",
             id: "id",
             userdata: "userdata"
         }
     });

});

我的控制器是这样的

   public ActionResult CompOffEdit(int Id,DateTime CompOffDate, string Description)
    {
        RegisterCompOff r = db.RegisterCompOffs.Where(l=>l.Id==Id).SingleOrDefault();
        if (!(r == null))
        {
            r.CompOffDate = CompOffDate;
            r.Description = Description;
            db.Entry(r).State = EntityState.Modified;
            db.SaveChanges();
            return Content("true");
        }
        else
        {
            return Content("false");
        }

    }

当我试图将编辑保存到 db..我得到这个异常

The parameters dictionary contains a null entry for parameter 'idnr' of non-nullable type 'System.Int32' for method 'System.Web.Mvc.ActionResult CompOffEdit(Int32, System.DateTime, System.String)' in 'AGS.Hrms.Controllers.CompOffController'. An optional parameter must be a reference type, a nullable type, or be declared as an optional parameter. Parameter name: parameters

用户只能在此处编辑补偿日期和描述...并且我从数据库中选择的 id 字段被隐藏。

谁能帮我解决这个问题

【问题讨论】:

    标签: jquery asp.net-mvc jqgrid


    【解决方案1】:

    您应该将CompOffEdit 操作的idnr 参数重命名为id,或者您应该将在行编辑期间发送到服务器的参数的默认id 名称重命名为idnr。您可以为此使用 jqGrid 的prmNames: {id: "idnr"} 选项。

    以同样的方式,您应该将CompOffEdit 操作的compOff 参数重命名为CompOffDate,并将reason 重命名为Description。或者,您可以使用具有CompOffDateDescription 作为属性的类实例作为CompOffEdit 操作的参数。在这种情况下,CompOffDateDescription 属性将使用编辑行中的值进行初始化。

    【讨论】:

    • 无论你说什么,加上我必须从我的数据库中将此 id 参数作为隐藏字段发送以查看并使其可编辑,因此当用户进行内联编辑时,此值将位于 Id 字段中我的compoffedit方法。我已经更新了我的代码。
    猜你喜欢
    • 1970-01-01
    • 2012-10-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-11-12
    相关资源
    最近更新 更多