zoukankan      html  css  js  c++  java
  • mvc jquery ajax传递数组null问题

    mvc jquery ajax传递数,  areaIds是个int数组。后台action用list<int>接收。当我想传空值时,先用null传递,结果action收到的AreaIds竟然含有一个元素0,非常诡异,有空再查找具体原来。后来想传空时不再用Null,改成[],这样就ok了。很奇怪

     function refreshStoreHouseDatas(marketId,areaIds,selectedValues) {
                var data = {
                    marketId: marketId,
                    areaIds: areaIds
                };
                var url = "@Url.Action("LoadStoreHousesByAreaIds", "CommonAjax")";
                $.post(url, data, function(result) {
                    $("#StoreHouseIds").data("kendoMultiSelect").setDataSource(result);
                    $("#StoreHouseIds").data("kendoMultiSelect").enable(true);
                    if (selectedValues!=null) {
                        $("#StoreHouseIds").data("kendoMultiSelect").value(selectedValues);
                    }
                });
            };

    action

     [HttpPost]
            public ActionResult LoadStoreHousesByAreaIds(LoadStoreHousesByAreaIdsRequest request)
            {
                List<StoreHouse> storeHousesList;
                if (request.AreaIds.Any())
                {
                    storeHousesList = _commonService.GetEquipmentStoreHouses(request.AreaIds);
                }
                else
                {
                    request.AreaIds = _commonService.ConvertToLeafChildAreas(new List<int>{ request.MarketId}).Select(m=>m.Id).ToList();
                    storeHousesList = _commonService.GetEquipmentStoreHouses(request.AreaIds);
                }
                var storeHouses = storeHousesList.Select(x => new SelectListItem
                {
                    Value = x.Id.ToString(),
                    Text = x.Name
                }).ToList();
    
                return Json(storeHouses, JsonRequestBehavior.AllowGet);
            }
  • 相关阅读:
    JavaScript闭包
    JavaScript的作用域与作用域链
    运动曲线提升CSS动画效果
    设计一个应用或网站时的流程
    JavaScript 与函数式编程
    声明式编程与命令式编程
    call(),apply()和bind()
    linux-xargs
    linux -shell
    linux-awk
  • 原文地址:https://www.cnblogs.com/taoshengyujiu/p/10347407.html
Copyright © 2011-2022 走看看