.aspx页面
<%@ Page Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage" %>
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
主页
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<script type="text/javascript" src="../../Scripts/jquery-1.4.1.min.js"></script>
<div>
<input type="button" id="button1" value="提交" onclick="on_Click();" />
<ul id="ul_li"></ul>
</div>
<script type="text/javascript">
$(function () {
$.ajax({
type: "post",
data: "",
async: true, //异步
url: '<%=Url.Action("gClass","Home") %>',
cache: false, //不加载缓存
success: function (result) {
var jsonResult = result;
for (var json in jsonResult) {
$("#ul_li").append($("<li>" + jsonResult[json].Name + "|||" + jsonResult[json].ID + "</li>"));
}
},
error: function () {
alert("请求失败");
}
})
// })
})
</script>
</asp:Content>
Controllers层
public JsonResult gClass()
{
List<ClassInfo> list = SqlConn.cList();
return Json(list);
}
数据层
public static List<ClassInfo> cList()
{
List<ClassInfo> list = new List<ClassInfo>();
ClassInfo cinfo;
for (int i = 0; i < 10; i++)
{
cinfo = new ClassInfo();
cinfo.ID = i;
cinfo.Name = "UserName" + i;
cinfo.set = true;
cinfo.Address = "北京市" + i;
list.Add(cinfo);
}
return list;
}