首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >为什么我的jqGrid不能传递额外的表单数据?

为什么我的jqGrid不能传递额外的表单数据?
EN

Stack Overflow用户
提问于 2012-09-21 01:19:05
回答 1查看 936关注 0票数 0

我正在使用带有jqGrid的ASP.Net MVC4,并且在jqGrid添加/编辑记录时,我尝试将一个附加值从表单传递到Add和Edit控制器方法中。我的jqGrid看起来像这样:

代码语言:javascript
复制
$('#jqgRulesSetupVariablesList').jqGrid({
    data: JSON.stringify(("#GroupDDL").valueOf()),
    contentType: 'application/json; charset=utf-8',
    //url from wich data should be requested
    url: '@Url.Action("GetRulesSetupVariables")',
    ondblClickRow: function (rowid) {
    jQuery(this).jqGrid('editGridRow', rowid,
        { url: '@Url.Action("UpdateRulesSetupVariable")', recreateForm: true, closeAfterEdit: true, closeOnEscape: true, reloadAfterSubmit: false });
    },
    //type of data
    datatype: 'json',
    //url access method type
    mtype: 'POST',
    //columns names
    colNames: ['ID', 'Name', 'Description', 'Type'],
    //columns model
    colModel: [
        { name: 'ID', index: 'ID', align: 'left', width: '30px', editable: false, key: true },
        { name: 'Name', index: 'Name', align: 'left', width: '100px', editable: true, edittype: 'text', editoptions: { maxlength: 20 }, editrules: { required: true } },
        { name: 'Description', index: 'Description', align: 'left', width: '260px', editable: true, edittype: 'text', editoptions: { maxlength: 80 }, editrules: { required: true } },
        { name: 'Type', index: 'Type', align: 'left', width: '25px', editable: true, edittype: 'text', editoptions: { maxlength: 1 }, editrules: { required: true } },
    ],
    //pager for grid
    pager: $('#jqgRulesSetupVariablesPaging'),
    //number of rows per page
    rowNum: 10,
    //initial sorting column
    sortname: 'Name',
    //initial sorting direction
    sortorder: 'asc',
    //we want to display total records count
    viewrecords: true,
    //grid height
    height: 230,
    width: 450,
});

$('#jqgRulesSetupVariablesList').jqGrid('navGrid', '#jqgRulesSetupVariablesPaging',
    { add: true, del: false, edit: true, search: false },
    // Edit Options
    { url: '@Url.Action("UpdateRulesSetupVariable")', closeAfterEdit: true, closeOnEscape: true, editData: { GroupName: function () { return "ABC"; } } },
    // Add Options
    { url: '@Url.Action("InsertRulesSetupVariable")', closeAfterAdd: true, closeOnEscape: true, editData: { GroupName: function () { return "ABC"; } } },
    // Delete options
    {}
);

我的控制器是:

代码语言:javascript
复制
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult UpdateRulesSetupVariable(RulesSetupVariableViewModel viewModel, string GroupName)
{
    bool updateSuccess = UpdateRulesSetupVariable_Internal(viewModel);

    return Json(updateSuccess);
}

[AcceptVerbs(HttpVerbs.Post)]
public ActionResult InsertRulesSetupVariable(RulesSetupVariableViewModel viewModel, string GroupName)
{
    bool updateSuccess = UpdateRulesSetupVariable_Internal(viewModel);

    return Json(updateSuccess);
}

我的模型是:

代码语言:javascript
复制
public class RulesSetupVariableViewModel
{
    public int ID { get; set; }
    public string Name { get; set; }
    public string Description { get; set; }
    public string Type { get; set; }
}

ID,Name,Description和Type都很好,但是GroupName不是。

你知道我哪里做错了吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-09-21 01:35:04

我想通了。愚蠢的错误。我正在使用doubleClick编辑行。我修改了这行

代码语言:javascript
复制
jQuery(this).jqGrid('editGridRow', rowid,
    { url: '@Url.Action("UpdateRulesSetupVariable")', 
      recreateForm: true, 
      closeAfterEdit: true, 
      closeOnEscape: true, 
      reloadAfterSubmit: false });
},

要这样做:

代码语言:javascript
复制
jQuery(this).jqGrid('editGridRow', rowid,
    { url: '@Url.Action("UpdateRulesSetupVariable")', 
      recreateForm: true, 
      closeAfterEdit: true, 
      closeOnEscape: true, 
      reloadAfterSubmit: false,
      editData: { GroupName: function () { return $("#GroupDDL").val(); } } 
},

这解决了我的问题。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/12517629

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档