Advertisement
Guest User

Untitled

a guest
Jun 23rd, 2015
319
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.66 KB | None | 0 0
  1. <!---- //End-bottom-grids---->
  2. <!--- //End-content---->
  3. <!--- //Them phan nay vao _Layout.cshtm---->
  4. @RenderSection("load", required: false)
  5. <!---start-footer---->
  6. -----------------------------------
  7. Sau do add moi 1 PartialView ten la _viewIndex trong thu muc Home
  8. @using PagedList.Mvc
  9. @using PagedList
  10. @model PagedList.IPagedList<MvcApplication2.Models.Product>
  11.  
  12. @foreach (var item in Model.Select((model, index) => new { model, index }))
  13. {
  14.  
  15. <div onclick="location.href='/Product/ProductDetails/@Html.DisplayFor(modelItem => item.model.id)';" class="@((item.index+1) % 3 == 0 ? "product-grid fade last-grid": "product-grid fade")">
  16. <div class="product-grid-head">
  17. <ul class="grid-social">
  18. <li><a class="facebook" href="#"><span> </span></a></li>
  19. <li><a class="twitter" href="#"><span> </span></a></li>
  20. <li><a class="googlep" href="#"><span> </span></a></li>
  21. <div class="clear"> </div>
  22. </ul>
  23. <div class="block">
  24. <div class="starbox small ghosting"> </div> <span> (46)</span>
  25. </div>
  26. </div>
  27. <div class="product-pic">
  28.  
  29. <a href="/Product/ProductDetails/@Html.DisplayFor(modelItem => item.model.id)"><img src="../images/product2.jpg" title="product-name" /></a>
  30. <p>
  31. <a href="/Product/ProductDetails/@Html.DisplayFor(modelItem => item.model.id)"><small>Nike</small> @Html.DisplayFor(modelItem => item.model.name) <small>Phantom</small> FG</a>
  32. <span>@Html.DisplayFor(modelItem => item.model.status)</span>
  33. </p>
  34. </div>
  35. <div class="product-info">
  36.  
  37. <div class="product-info-cust">
  38. @Html.ActionLink("Details", "ProductDetails", "Product", new { id = item.model.id }, null)
  39. </div>
  40. <div class="product-info-price">
  41.  
  42.  
  43.  
  44. <a href="/Product/ProductDetails/@Html.DisplayFor(modelItem => item.model.id)">&#163; @Html.DisplayFor(modelItem => item.model.price) </a>
  45.  
  46. </div>
  47. <div class="clear"> </div>
  48. </div>
  49. <div class="more-product-info">
  50. <span> </span>
  51. </div>
  52. </div>
  53. }
  54. <div class="clear"> </div>
  55. @Html.PagedListPager(Model, page => Url.Action("Index","Home", new { page }), PagedListRenderOptions.OnlyShowFivePagesAtATime)
  56. --------------------------
  57. sua lai controller Home
  58. public ActionResult Index(int page =1)
  59. {
  60. int numpage = page;
  61. int pagesize = 3;
  62. ViewData["numpage"] = numpage;
  63. List<Product> pr = ssde.Products.OrderBy(x => x.date_create).ToList();
  64.  
  65. return Request.IsAjaxRequest()
  66. ? (ActionResult)PartialView("_viewIndex", pr.ToPagedList(numpage, pagesize))
  67. : View(pr.ToPagedList(numpage, pagesize));
  68. }
  69. ------------------------------
  70. Index.cshtml thi thay the phan nay
  71. <p> Sản phẩm mới nhất</p>
  72. <div id="_viewIndex">
  73. @Html.Partial("_viewIndex", Model)
  74. </div>
  75.  
  76.  
  77. @section load{
  78. <script type="text/javascript">
  79. function ChangeUrl(page, url) {
  80. if (typeof (history.pushState) != "undefined") {
  81. var obj = { Page: page, Url: url };
  82. history.pushState(obj, obj.Page, obj.Url);
  83. } else {
  84. alert("Browser does not support HTML5.");
  85. }
  86.  
  87.  
  88. }
  89. function search() {
  90. $.ajax({
  91.  
  92. url: "/Home/Index?page=2",
  93. success: function (result) {
  94. ChangeUrl("Index", "/Home/Index?page=2");
  95. $('#_viewIndex').html(result);
  96. }
  97. });
  98. }
  99. function search1() {
  100. $.ajax({
  101.  
  102. url: "/Home/Index?page=1",
  103. success: function (result) {
  104. ChangeUrl("Index", "/Home/Index?page=1");
  105. $('#_viewIndex').html(result);
  106. }
  107. });
  108. }
  109.  
  110. $(function () {
  111. $('#a').click(function () {
  112. search();
  113. })
  114. $('#test').click(function () {
  115. search();
  116. })
  117. $('#b').click(function () {
  118. search1();
  119. })
  120.  
  121. $('body').on('click', '#_viewIndex .pagination a', function (event) {
  122. event.preventDefault();
  123. console.log('page');
  124. var url1 = $(this).attr('href');
  125. console.log(url1);
  126.  
  127. $.ajax({
  128. url: url1,
  129. success: function (result) {
  130. ChangeUrl('Index', url1);
  131. $('#_viewIndex').html(result);
  132. }
  133. });
  134. });
  135. })
  136. </script>
  137. }
  138. <div class="clear"> </div>
  139. </div>
  140. </div>
  141.  
  142.  
  143. <div class="clear">
  144.  
  145. </div>
  146.  
  147. </div>
  148. </div>
  149.  
  150. </body>
  151. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement