ASP.NET MVC2 利用Json获取数据

  <script src="http://www.cnblogs.com/Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(
function () {
$(
"#btnJson").click(function () {
$.get(
'<%= Url.Action("Json") %>', { date: new Date().getTime() }, function (data) {
var str = "";
for (var i = 0; i < data.length; i++) {
str
+= "id:" + data[i].id + "名称:" + data[i].name + "<br>";
}
document.write(str);
},
"json");
});
});
</script>

 

<body>
<div>
<button id="btnJson">
获取
</button>
</div>
</body>

  

        public ActionResult Json()
{
ArrayList json
= new ArrayList();
for (int i = 0; i < 100; i++)
{
json.Add(
new { id = i, name = "编号" + i });
}
// var json = new { name = "nie.jl", age = 13 };
return Json(json, JsonRequestBehavior.AllowGet);

}

  

原文地址:https://www.cnblogs.com/yannis/p/2133762.html