• 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);
            }
  • 相关阅读:
    记录ci框架中定时任务的执行
    2019 年MySQL面试题及答案
    Net线程问题解答(转)
    vs2005 Team System的版本
    ASP.NET 安全认证(如何运用 Form 表单认证)
    .net调用存储过程时的输出函数
    在服务器执行js脚本
    简单的批量更新(小技巧)
    UNION 和UNION ALL 的区别
    ServerVariable(环境变量)
  • 原文地址:https://www.cnblogs.com/taoshengyujiu/p/10347407.html
Copyright © 2020-2023  润新知