mvc jquery ajax傳遞數組null問題

mvc jquery ajax傳遞數,  areaIds是個int數組。後臺action用list<int>接收。當我想傳空值時,先用null傳遞,結果action收到的AreaIds居然含有一個元素0,很是詭異,有空再查找具體原來。後來想傳空時再也不用Null,改爲[],這樣就ok了。很奇怪jquery

 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);
                }
            });
        };

 

 

actionajax

 [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);
        }
相關文章
相關標籤/搜索