我有一个现有的项目,我需要维护,但是这是我第一次满足的jqGrid ...理解jqGrid的添加方法和Ajax请求
主要是,我有一个Product,即可以有多个Formule小号。每个Formule可以包含多个Period。 A Period由DepartureDate和Price来描述。
这是管理期间网格的代码。特别是它增加了网格的导航器的可能性添加Period s。
当在网格中添加新行时,用户填充包含2个字段的表单:DepartureDate和与新创建的期间相对应的Price。
jQuery("#periode-grid").jqGrid(
'setGridParam',
{
postData: {
formuleId: rowid // <<< !!!
},
datatype: "json"
})
.navGrid("#periode-pager",
{
"edit": false, "add": true, "del": false,
"search": true, "addtext": "@Resources.Main.Grid_Add"
},
{},
{
"url": '@Url.Action("AddAjaxPeriod",
new { elementId = @ViewData["ProductId"] })', // <<< !!!
"closeOnEscape": true, "closeAfterAdd": true,
"reloadAfterSubmit": true, "width": 500,
"beforeSubmit": BeforeFormuleSubmit
});
,这是我AddAjaxPeriod签名,包含4个参数,包括日期和价格:
[HttpPost]
[AjaxRequestOnly]
[Transaction]
public JsonResult AddAjaxPeriod(Guid elementId, Guid formuleId,
DateTime departureDate, double price)
{ ... }
现在一切工作正常,直到我打开窗体中添加价格和日期,填空题要求的日期和价格,然后点击验证。
我得到一个错误,指出AddAjaxPeriod请求departureDate非可选参数,不填写的...我可以通过匿名方法达成一致,我填写的elementId的formuleId设置在postData,但用户尝试添加的形式为departureData和price。有没有办法获得“添加表单”(日期和价格)的值并将它们传递给AddAjaxPeriod方法?
编辑:
的奥列格发言后,我发现网格初始化(在occurence在母体部分视图)。这是代码:
jQuery("#periode-grid").jqGrid({
"url": '@Url.Action("PeriodePagedList", new { elementId = ViewData["ProductId"] })',
"datatype": 'local',
"mtype": 'POST',
"width": 400,
"height": 100,
"colNames": [
"@Resources.Catalog_Products.FormulePeriode_DepartureDate",
"@Resources.Catalog_Products.FormulePeriode_Price",
"" // Actions
],
"colModel": [
{ "name": 'DepartureDate', "index": 'DepartureDate', "editable": true, "align": 'center', "width": 100, "sorttype": 'date', "datefmt": 'dd/mm/yyyy', "editoptions": { "dataInit": function (element) { jQuery(element).datepicker({ "dateFormat": 'dd/mm/yy', "minDate": 0, "showAnim": '' }) } }, "editrules": { "required": true, "date": true } },
{ "name": 'Price', "index": 'Price', "editable": true, "align": 'center', "editrules": { "required": true }, "width": 100, "formatter": currencyFormatter, "unformat": unformatCurrency },
{ "name": 'Actions', "index": 'Actions', "width": 50, "align": 'center', "search": false, "sortable": false }
],
"sortname": 'DepartureDate',
"rowNum": 100,
"loadComplete": OnLoadPeriodeComplete,
"pager": jQuery('#periode-pager'),
"pginput": false,
"pgbuttons": false,
"viewrecords": false,
"imgpath": '@Url.Content("~/Content/jqueryui/images")',
"caption": "@Resources.Catalog_Products.FormulePeriode_GridTitle",
"shrinkToFit": true,
"hidegrid": false
});
2014-02-20
Serge