jqGrid的:通过选择ID作为HTML表单参数 [英] jqGrid: pass selected IDs as HTML form parameters
问题描述
我有一个HTML表单(剃刀)与jqGrid的选择实体(请假设客户,例如)。
客户的jqGrid如下:
I have an HTML form (Razor) with jqGrid to select entities (please assume customers, for example). The customers jqGrid looks like:
jQuery("#ajaxGrid").jqGrid({
url: '@Url.Action("CustomersData")',
datatype: 'json',
mtype: 'GET',
jsonReader: { repeatitems: false, id: "Id" },
colNames: ['Id', 'Name'],
colModel: [
{ name: 'Id', editable: true, sortable: false, hidden: false },
{ name: 'Name', editable: true, sortable: false, hidden: false }
],
multiselect: true,
viewrecords: true,
rowNum: 5,
width: '850',
height: '15em'
});
因此,网格允许多选。
So, the grid allows multiple selection.
现在的问题是:如何通过选择客户ID(为IEnumerable)控制器上提交(到相应的提交操作)
The question is: how to pass selected customer IDs (as IEnumerable) to the controller on submit (to the appropriate submit action)?
我想它可以通过设置所有选定的ID作为表单参数来完成。我不知道如何将数据从阵列复制:
I guess it can be done by setting all selected IDs as form parameter. I don't know how to copy the data from the array:
var ids = jQuery("#ajaxGrid").getGridParam('selarrrow');
于HTML表单隐藏价值。
to HTML form hidden value.
推荐答案
如果我理解你正确,你可以创建例如字符串对于的ids.join选定行的逗号分隔的IDS(' ')
。然后你可以使用 jQuery.val(newValue)以
来设置新halue的隐藏字段: $(#hiddenFieldId)VAL( ids.join(''));
If I understand you correct you can for example create string with comma-separated ids of selected rows with respect of ids.join(',')
. Then you can use the jQuery.val(newValue)
to set the new halue to the hidden field: $("#hiddenFieldId").val(ids.join(','));
.
这篇关于jqGrid的:通过选择ID作为HTML表单参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!