首页 > 代码库 > MVC 简单的AJAX异步分页+MYSQL

MVC 简单的AJAX异步分页+MYSQL

留资料,以后学习用

1.后台

        public ActionResult textPage()        {            return View();        }        [HttpPost]        public ActionResult textPage(FormCollection collection)        {            //实例化对象            BLL.pc_dialog bll_pcdialog = new BLL.pc_dialog();            Model.pc_dialog model_pcdialog = new Model.pc_dialog();            //a=当前页码 b=页码显示量            int a = int.Parse(Request["currentpage"]) - 1;            string b = Request["pagesize"];            //SQL语句            string sqlString = "select * from pc_dialog order by Dia_Id limit " + a + "," + b;            //查出来需要的页码然后将DATASET转化为LIST,具体转化方式百度            List<Model.pc_dialog> list = ConvertHelper<Model.pc_dialog>.ConvertToList(DbHelperMySQL.Query(sqlString).Tables[0]);            //Json不能接受DATSET 只能接收list            return Json(list);        }
MVC简单的AJax异步分页

2.前台

<html><head>    <title>FindArchiveTable</title>    <script src="../../Scripts/jquery-1.7.2.min.js" type="text/javascript"></script>    <script type="text/javascript">       //页面加载时候调用局部刷新        $(function () {            page(1, 10);        })        function page(currentpage, pagesize) {            $(#tb).html(‘‘);            $.post("/PC/textPage"/*URL*/, { currentpage: currentpage, pagesize: pagesize}/*回传值*/, function (obj) {                var tr = "<tr><th> 编号</th><th>姓名 </th> </tr>"; /*抬头*/                console.info(obj.length); /*列表长度*/                for (var i = 0; i < obj.length; i++) {                    /*循环调取值给予tr*/                                        tr += "<tr><td>" + obj[i].Dia_Id + "</td><td> " + obj[i].Pro_Id + "</td></tr>";                }                /*将Table更新,这里要和ID对应*/                console.info(tr);                $(tr).appendTo($(#tb));            })        }    </script></head><body>    <table id="tb">    </table>    <ul>        <li><a href="javascript:" onclick="page(1,10)">1</a></li>         <li><a href="javascript:" onclick="page(2,10)">2</a></li>        <li><a href="javascript:" onclick="page(3,10)">3</a></li>    </ul></body></html>
MVC简单的AJAX异步分页前端

 

MVC 简单的AJAX异步分页+MYSQL