Advertisement
Guest User

Untitled

a guest
Jul 1st, 2015
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.68 KB | None | 0 0
  1. public ActionResult Index(string brand_name, int? page)
  2. {
  3. //returns IQueryable<Product> representing an unknown number of products. a thousand maybe?
  4. //var products = MyProductDataSource.FindAllProducts();
  5. ViewData["brand_name"] = brand_name;
  6. // if no page was specified in the querystring, default to the first page (1)
  7. var pageNumber = page.HasValue ? page.Value : 1;
  8.  
  9. //ViewBag.OnePageOfProducts = onePageOfProducts;
  10.  
  11. if (!string.IsNullOrWhiteSpace(brand_name))
  12. {
  13. // will only contain 12 products max because of the pageSize
  14. IPagedList<Material> onePageOfProducts = db.EContent_MaterialsFinalViewWithBcos
  15. .Select(i => new Material
  16. {
  17. Brand = i.Brand,
  18. Category = i.Category,
  19. Language = i.Language,
  20. Bco = i.Bco,
  21. MaterialCod = i.MaterialCod,
  22. Derivation = i.Derivation,
  23. Artwork = i.Artwork,
  24. BcoDelivery = i.BcoDelivery,
  25. MaterialId = i.MaterialId
  26. })
  27. .Where(p => p.Brand.ToLower() == brand_name.ToLower())
  28. .OrderBy(i => i.MaterialCod)
  29. .ToPagedList<Material>(pageNumber, defaultPageSize);
  30.  
  31. return View("Index", onePageOfProducts);
  32. }
  33. else
  34. {
  35. // will only contain 12 products max because of the pageSize
  36. IPagedList<Material> onePageOfProducts = db.EContent_MaterialsFinalViewWithBcos
  37. .Select(i => new Material
  38. {
  39. Brand = i.Brand,
  40. Category = i.Category,
  41. Language = i.Language,
  42. Bco = i.Bco,
  43. MaterialCod = i.MaterialCod,
  44. Derivation = i.Derivation,
  45. Artwork = i.Artwork,
  46. BcoDelivery = i.BcoDelivery,
  47. MaterialId = i.MaterialId
  48. }).OrderBy(i => i.MaterialCod).ToPagedList<Material>(pageNumber, defaultPageSize);
  49.  
  50. return View("Index", onePageOfProducts);
  51. }
  52. }
  53.  
  54. @using PagedList.Mvc <!--import this so we get our HTML Helper-->
  55.  
  56. @model IPagedList<eContentMVC.Models.Material>
  57.  
  58. <div style="padding-top: 5px"></div>
  59. @using (Html.BeginForm("Index", "Materials", FormMethod.Get))
  60. {
  61. <div class="col-lg-3">
  62. <div class="input-group">
  63. <span class="input-group-btn">
  64. <button class="btn btn-default" type="submit"><i class="glyphicon glyphicon-search"></i> Search</button>
  65. </span>
  66. <input class="span2" id="appendedInputButton" type="text" name="brand_name" placeholder="Search Brand for..." />
  67. </div><!-- /input-group -->
  68. </div><!-- /.col-lg-3 -->
  69. <div style="padding-top: 20px"></div>
  70. <div id="grid-list">
  71. @{ Html.RenderPartial("_AjaxMaterialList", Model); }
  72. </div>
  73. }
  74.  
  75. @using PagedList.Mvc <!--import this so we get our HTML Helper-->
  76.  
  77. @model IPagedList<eContentMVC.Models.Material>
  78.  
  79. <table>Some table here</table>
  80. <div class="panel panel-primary filterable">
  81. <div class="centerAlign">
  82. <!-- output a paging control that lets the user navigation to the previous page, next page, etc -->
  83. @Html.PagedListPager(Model, page => Url.Action("Index", "Materials", new
  84. {
  85. //It would be awesome if I could have some brand_name = brand
  86. page
  87. }))
  88. </div>
  89. </div>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement