C# extJs 用jsonl来进行前后台传递数据

前台extjs代码
var changeUnit = function (newValue) {
        var record = App.LineGrid.getSelectionModel().getSelection()[0];
        Ext.net.directRequest({
            cleanRequest: true,
            //要传递数据的url
            url: '/PurchaseOrder/GetSkuInfo',
            eventMask: { showMask: true },
           //传递数据到后台
            extraParams: { skuCode: record.data.SkuCode, itemId: record.data.ItemId },
            success: function (request, result) {
                var newRecord = Ext.JSON.decode(request.responseText);
                if (newValue == newRecord.Unit) {
                //给页面赋值
                    record.set("11", 1);
                    record.set("22", 2);
                    record.set("33", 3);
                }
                else {
                 //给页面赋值
                    record.set("11", 1);
                    record.set("22", 2);
                    record.set("33", 3);
                }
            },
            failure: function (request, result) {
            }
        });
    };

后台代码

public ActionResult GetInfo(string skuCode, int itemId)
        {
            var skuInfo = _itemRepository.GetSkus().FirstOrDefault(r => r.SkuCode == skuCode);
            if (skuInfo != null)
            {
            //返回json数据
                return Json(skuInfo);
            }
            else
            {
                return Json(new { success = true, data = "" }, JsonRequestBehavior.AllowGet);
            }
        }

个人觉得extjs就是对ajax的一个完整的封装,使用起来很方便

你可能感兴趣的:(C# extJs 用jsonl来进行前后台传递数据)