asp.net MVC項目開發之統計圖echarts後台資料的處理(三)

來源:互聯網
上載者:User

標籤:

前台顯示的東西,有相應的文檔很容易修改,後台傳遞資料方式才是我們最關心的

首先要記住,我們一步資料使用的是post,那麼後台代碼我們要給方法加上 [HttpPost]註解

不然非同步沒有效果

下面上代碼,為了節省時間,欄位變數的命名,我用的是英文1,2,3,不要見怪哦

 public ActionResult GetMarriageList(int areaId, int level)        {            List<VwAllPersonInfoModel> allPerList = new List<VwAllPersonInfoModel>();            IVwAllPersonInfoService allPerService = LoadService<IVwAllPersonInfoService>();            Dictionary<string, Object> json = new Dictionary<string, Object>();            DdlDataSrc ddl = new DdlDataSrc();            DataTable dt = new DataTable();            Criteria c = new Criteria();            StringBuilder sb = new StringBuilder();            ddl.getAllChildAreaIds(sb, areaId);            #region 根據地區把擷取的資料放入json            int one = 0;            int two = 0;            int three = 0;            int four = 0;            if (level == 3)            {                c.AddWhere("AreaId", areaId);                allPerList = allPerService.GetAllVwAllPersonInfoModel(c);            }            else if (level != 0)            {                string str = sb.Remove(sb.Length - 1, 1).ToString();                dt = allPerService.GetAllPersonInfoCharts(str, 0, 0);                allPerList = (List<VwAllPersonInfoModel>)ModelConvertHelper<VwAllPersonInfoModel>.ConvertToModel(dt);            }            if (allPerList.Count != 0)            {                for (int i = 0; i < allPerList.Count; i++)                {                    switch (allPerList[i].MaticalStatus)//婚姻狀況                    {                        case 1:                            ++one;                            break;                        case 2:                            ++two;                            break;                        case 3:                            ++three;                            break;                        case 4:                            ++four;                            break;                    }                }                json.Add("未婚", one);                json.Add("已婚有配偶", two);                json.Add("離婚", three);                json.Add("喪偶", four);            }            else            {                json.Add("暫無資料", 1);            }            #endregion            return Json(json);        }
View Code 

 這裡使用 Dictionary<string, Object> json = new Dictionary<string, Object>();Dictionary的結構是這樣的:Dictionary<[key], [value]>提供快速的索引值尋找的方式,把輸入非同步給統計圖。

如果資料是單選的,可以使用switch進行判斷,如果是多選的話,請使用if進行判斷。分享出來希望能幫到大家

asp.net MVC項目開發之統計圖echarts後台資料的處理(三)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.