码迷,mamicode.com
首页 > 编程语言 > 详细

mvc jquery ajax传递数组null问题

时间:2019-02-02 10:32:19      阅读:225      评论:0      收藏:0      [点我收藏+]

标签:item   tor   空值   元素   list()   col   ISE   null   style   

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

 

mvc jquery ajax传递数组null问题

标签:item   tor   空值   元素   list()   col   ISE   null   style   

原文地址:https://www.cnblogs.com/taoshengyujiu/p/10347407.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!