gpt4 book ai didi

asp.net-mvc - 如何同时将表单数据和jqGrid(editUrl)数据传递给Controller

转载 作者:行者123 更新时间:2023-12-03 23:00:53 24 4
gpt4 key购买 nike

我有一个 asp.net MVC3 应用程序,其中包含各种表单数据和 jqGrid。

当我在 jqGrid 中编辑一行时,我需要将网格数据以及一些表单片段发布到 editUrl Controller 。

我可以通过 editUrl 将 jqGrid 编辑的数据发布到我的 Controller 。

有办法做到这一点吗?

我不确定如何发送其他表单元素以及如何在我的 Controller 中接收它们。

任何帮助将不胜感激。

下面是我的 jqGrid:

    $("#jqTable").jqGrid({
// Ajax related configurations
url: '@Url.Action("_CustomBinding")',
datatype: "json",
mtype: "POST",
postData: {
programID: function () { return $("#ProgramID option:selected").val(); },
buildID: function () { return $('#Builds option:selected').val(); }
},

// Specify the column names
colNames: ["Actions", "Assembly ID", "Assembly Name", "Assembly Type", "Cost", "Order", "Budget Report", "Partner Request", "Display"],

// Configure the columns
colModel: [
{ name: 'myac', width: 80, fixed: true, sortable: false, resize: false, formatter: 'actions', formatoptions: { keys: true} },
{ name: "AssemblyID", key: true, index: "AssemblyID", width: 40, align: "left", editable: false },
{ name: "AssemblyName", index: "AssemblyName", width: 100, align: "left", editable: true, edittype: 'select',
editoptions: {
dataUrl: '@Url.Action("_Assemblies")',
buildSelect: function (data) {
var response = jQuery.parseJSON(data);
var s = '<select>';
if (response && response.length) {
for (var i = 0, l = response.length; i < l; i++) {
var ri = response[i];
s += '<option value="' + ri + '">' + ri + '</option>';
}
}
return s + "</select>";
}
}
},
{ name: "AssemblyTypeName", index: "AssemblyTypeName", width: 100, align: "left", editable: false, edittype: 'select' },
{ name: "AssemblyCost", index: "AssemblyCost", width: 50, align: "left", formatter: "currency", editable: true },
{ name: "AssemblyOrder", index: "AssemblyOrder", width: 50, align: "left", editable: true },
{ name: "AddToBudgetReport", index: "AddToBudgetReport", width: 100, align: "center", formatter: "checkbox", editable: true, edittype: 'checkbox' },
{ name: "AddToPartnerRequest", index: "AddToPartnerRequest", width: 100, align: "center", formatter: "checkbox", editable: true, edittype: 'checkbox' },
{ name: "Show", index: "Show", width: 50, align: "center", formatter: "checkbox", editable: true, edittype: 'checkbox'}],

// Grid total width and height and formatting
//width: 650,
//height: 220,
altrows: true,

// Paging
//toppager: true,
pager: $("#jqTablePager"),
rowNum: 10,
rowList: [10, 20, 30],
viewrecords: true, // Specify if "total number of records" is displayed
emptyrecords: 'No records to display',

// Default sorting
sortname: "AssemblyID",
sortorder: "asc",

// Grid caption
caption: "Build Template",

// grid command functionality
editurl: '@Url.Action("_AjaxUpdate")',
onSelectRow: function (AssemblyID) {
if (AssemblyID && AssemblyID !== lastsel) {
$('#jqTable').jqGrid('restoreRow', lastsel);
$("#jqTable").jqGrid('editRow', AssemblyID, true);
lastsel = AssemblyID;
}
}
}).navGrid("#jqTablePager",
{ refresh: false, add: false, edit: false, del: false },
{}, // settings for edit
{}, // settings for add
{}, // settings for delete
{sopt: ["cn"]} // Search options. Some options can be set on column level
);

最佳答案

您可以使用 onclickSubmit 选项自定义发送到服务器的内容:

.navGrid("#jqTablePager",
{ refresh: false, add: false, edit: false, del: false },
{ // settings for edit
onclickSubmit: function(params, postdata)
{
postdata.extraParam = 'value'
}
},
{}, // settings for add
{}, // settings for delete
{sopt: ["cn"]} // Search options. Some options can be set on column level
);

Controller 将接收一个 JSON 对象,其中包含所有已编辑的属性 + extraParam。这取决于您如何在服务器端处理此问题。

关于asp.net-mvc - 如何同时将表单数据和jqGrid(editUrl)数据传递给Controller,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8512097/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com