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);
            }
  • 相关阅读:
    mac命令
    缓存穿透、缓存击穿、缓存雪崩区别
    计算属性 和 方法的区别
    Docker笔记
    使用excel 生成多个 sql语句
    开发分支操作步骤
    Python3.8中使用pymysql连接数据报错__init__() takes 1 positional argument but 5 were given解决方案
    测试时间评估
    js map() 函数的使用 --待补充
    左联后再内联的2种写法
  • 原文地址:https://www.cnblogs.com/taoshengyujiu/p/10347407.html
Copyright © 2011-2022 走看看