jqgrid和ajax的区别,理解jqGrid的添加方法和Ajax请求
我有一個現(xiàn)有的項目,我需要維護,但是這是我第一次滿足的jqGrid ...理解jqGrid的添加方法和Ajax請求
主要是,我有一個Product,即可以有多個Formule小號。每個Formule可以包含多個Period。 A Period由DepartureDate和Price來描述。
這是管理期間網(wǎng)格的代碼。特別是它增加了網(wǎng)格的導航器的可能性添加Period s。
當在網(wǎng)格中添加新行時,用戶填充包含2個字段的表單:DepartureDate和與新創(chuàng)建的期間相對應的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個參數(shù),包括日期和價格:
[HttpPost]
[AjaxRequestOnly]
[Transaction]
public JsonResult AddAjaxPeriod(Guid elementId, Guid formuleId,
DateTime departureDate, double price)
{ ... }
現(xiàn)在一切工作正常,直到我打開窗體中添加價格和日期,填空題要求的日期和價格,然后點擊驗證。
我得到一個錯誤,指出AddAjaxPeriod請求departureDate非可選參數(shù),不填寫的...我可以通過匿名方法達成一致,我填寫的elementId的formuleId設置在postData,但用戶嘗試添加的形式為departureData和price。有沒有辦法獲得“添加表單”(日期和價格)的值并將它們傳遞給AddAjaxPeriod方法?
編輯:
的奧列格發(fā)言后,我發(fā)現(xiàn)網(wǎng)格初始化(在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
《新程序員》:云原生和全面數(shù)字化實踐50位技術專家共同創(chuàng)作,文字、視頻、音頻交互閱讀總結(jié)
以上是生活随笔為你收集整理的jqgrid和ajax的区别,理解jqGrid的添加方法和Ajax请求的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 计算机显示器不清楚跟电池有关系吗,电脑液
- 下一篇: win服务器上文件消失,Winserve