码迷,mamicode.com
首页 > Web开发 > 详细

Asp.net MVC 示例

时间:2016-04-26 23:44:48      阅读:277      评论:0      收藏:0      [点我收藏+]

标签:

public ActionResult Browse(string id)
{
        using (musicstoreEntities db = new musicstoreEntities())
        {
                ViewBag.GenreId = id;
                int count = db.Albums.Count(a => a.GenreId.ToString() == id);
                int pageCount = 0;
                if (count%10 == 0)
                {
                    pageCount = count/10;
                }
                else
                {
                    pageCount = count/10 + 1;
                }
                ViewBag.AlbumCount = pageCount;
                return View();
        }
}

public ActionResult PageList(string id, int pageNum, int pageSize)
{
        List<string> albumTitleList = null;
        using (musicstoreEntities db = new musicstoreEntities())
        {
                albumTitleList =
                    db.Albums.Where(album => album.GenreId.ToString() == id).OrderBy(album => album.Title)
                        .Skip((pageNum - 1) * pageSize)
                        .Take(pageSize)
                        .ToList().Select(album => album.Title).ToList();
        }
        return Json(albumTitleList, JsonRequestBehavior.AllowGet);
}

<script>    

  $(function() {        

    //$.ajaxSetup({ cache: false });        

    var pageCount = Number($("#pageCount").val());        

    loadPageList(1, 10, pageCount);    

  });

  function loadPageList(pageNum, pageSize, pageCount) {        

    var genreid = $("#genreid").val();        

    $.get("/Store/PageList", { id: genreid, pageNum: pageNum, pageSize: pageSize }, function(data) {            

      $("#ulAlbumList").empty();            

      $(".pagination").empty();            

      $.each(data, function(index, item) {                

        $("#ulAlbumList").append("<li>" + item + "</li>");            

      });            

      $(".pagination").append(‘<li><span aria-label="Previous"><span aria-hidden="true">&laquo;</span></span></li>‘);            

      for (var i = 1; i <= pageCount; i++) {                

        $(".pagination").append("<li><span>" + i + "</span></li>");                

        if (pageNum === i) {                    

          $(".pagination li:eq(" + i + ")").addClass("active");                

        }            

      }            

      $(".pagination").append(‘<li><span aria-label="Next"><span aria-hidden="true">&raquo;</span></span></li>‘);

      if (Number(pageNum) === Number(pageCount)) {                

        $(".pagination li:last").addClass("disabled");            

      }            

      if (Number(pageNum) === 1) {                

        $(".pagination li:first").addClass("disabled");            

      }            

      getNextPageList(pageNum, pageSize, pageCount);            

      getPrePageList(pageNum, pageSize, pageCount);        

    });    

  }

  function getNextPageList(pageNum, pageSize, pageCount) {        

    $(".pagination li:last").click(function () {            

      loadPageList(Number(pageNum) + Number(1), pageSize, pageCount);        

    });    

  }

  function getPrePageList(pageNum, pageSize, pageCount) {        

    $(".pagination li:first").click(function() {            

      loadPageList(Number(pageNum) - Number(1), pageSize, pageCount);        

    });    

  }

</script>

Asp.net MVC 示例

标签:

原文地址:http://www.cnblogs.com/newstar87/p/5436989.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!