在controller里面写一个object返回类型的方法:如下

        public object CoustomLabelWikiReuslt()
        {
            IDictionary<int, string> CoustomLabels = GetCoustomLabel();
            IDictionary<int, int> LabelWikiCount = GetLabelWikiCount();
            IList<int> ids = new List<int>();
            IList<int> counts = new List<int>();
            IList<string> names = new List<string>();
            foreach (int k in CoustomLabels.Keys)
            {
                ids.Add(k);
                counts.Add(LabelWikiCount[k]);
                names.Add(CoustomLabels[k]);
            }
            return Json(new
            {
                IDS = ids,
                Names = names,
                wikiCount = counts,
            }, JsonRequestBehavior.AllowGet);
        }

这方法的return Json对象,传输三列数据,一一对应的三列数据。

在aspx页面的js代码里面写下面代码:

 $.get("/wiki/CoustomLabelWikiReuslt", function (data) {
            if (data != null) {
                if (data.IDS.length > 0) {
                    for (var i = 0; i < data.IDS.length; i++) {
                        $("#wikilabel ul").append("<li><a href='/wiki/search/id?lab=" + data.IDS[i] + "'>" + data.Names[i] + "(<span>" +

                        data.wikiCount[i] +  "</span>)</a></li>");
                    }
                }
            }
  });

用get方法异步获取对应的controller里面的方法,data会带回传回的值,也就是return的Json里面的new对象,所以data包含三列数据:IDS、Names、wikiCount

最后用for循环取三列的值,完美实现

相关文章:

  • 2021-08-27
  • 2022-12-23
  • 2021-09-18
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-08-21
猜你喜欢
  • 2022-02-19
  • 2022-02-02
  • 2021-12-26
  • 2021-12-18
  • 2021-08-24
  • 2021-09-19
  • 2021-09-09
相关资源
相似解决方案