jqgrid和ajax的区别,理解jqGrid的添加方法和Ajax请求

我有一个现有的项目,我需要维护,但是这是我第一次满足的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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值