Advertisement
Guest User

Untitled

a guest
Jun 23rd, 2015
252
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 16.55 KB | None | 0 0
  1. Layout
  2. ----------
  3. @RenderSection("searchnangcao", required: false)
  4. ------------
  5. controller
  6. ------------
  7. public ActionResult searchNangCao (int? page, string name, string price, string gender)
  8. {
  9. int _gender = Convert.ToInt32(gender);
  10. int _price = 100000;
  11. if(!String.IsNullOrEmpty(price) && Convert.ToInt32(price)!=null)
  12. {
  13. _price = Convert.ToInt32(price);
  14. }
  15.  
  16. string _name = name;
  17. int pageSize = 3;
  18. int numpage = (page ?? 1);
  19. var product = ssde.Products.AsQueryable();
  20. int temp = 0;
  21. if (_gender == 0)
  22. {
  23. if (!String.IsNullOrEmpty(name) || !String.IsNullOrEmpty(price))
  24. {
  25. if (String.IsNullOrEmpty(name))
  26. {
  27. product = ssde.Products.Where(p => p.price < _price).OrderBy(p => p.id);
  28. }
  29. else
  30. {
  31. if (String.IsNullOrEmpty(price))
  32. {
  33. product = ssde.Products.Where(p => p.name.ToLower().Contains(name.ToLower())).OrderBy(p => p.id);
  34. }
  35. else
  36. {
  37. product = ssde.Products.Where(p => p.name.ToLower().Contains(name.ToLower()) && p.price < _price).OrderBy(x => x.id);
  38. }
  39. }
  40.  
  41. temp = 1;
  42. }
  43. }
  44. else
  45. {
  46. if (String.IsNullOrEmpty(name))
  47. {
  48. product = ssde.Products.Where(p => p.price < _price && p.id_gender == _gender).OrderBy(p => p.id);
  49. }
  50. else
  51. {
  52. if (String.IsNullOrEmpty(price))
  53. {
  54. product = ssde.Products.Where(p => p.name.ToLower().Contains(name.ToLower())&& p.id_gender == _gender).OrderBy(p => p.id);
  55. }
  56. else
  57. {
  58. product = ssde.Products.Where(p => p.name.ToLower().Contains(name.ToLower()) && p.price < _price&& p.id_gender == _gender).OrderBy(x => x.id);
  59. }
  60. }
  61.  
  62. temp = 1;
  63. }
  64.  
  65. ViewBag.temp = temp;
  66. if(temp == 0)
  67. {
  68. product = product.OrderBy(x => x.id);
  69. }
  70. return Request.IsAjaxRequest()
  71. ? (ActionResult)PartialView("_viewSearchNangCao", product.ToPagedList(numpage, pageSize))
  72. : View(product.ToPagedList(numpage,pageSize));
  73. }
  74. ----------------------------------------
  75. tạo view mới tên là searchNangCao
  76. --------------------------------------
  77. @using MvcApplication2.Models
  78. @model PagedList.IPagedList<MvcApplication2.Models.Product>
  79. @using PagedList;
  80. @using PagedList.Mvc;
  81. @{
  82. ViewBag.Title = "Search";
  83. Layout = "~/Views/Shared/_Layout.cshtml";
  84. }
  85.  
  86.  
  87. <html>
  88. <body>
  89. <div class="clear"> </div>
  90. <!----//End-image-slider---->
  91. <!----start-price-rage--->
  92. <div class="wrap">
  93.  
  94. </div>
  95. <!----//End-price-rage--->
  96. <!--- start-content---->
  97. <div class="content">
  98. <div class="wrap">
  99. <div class="content-left">
  100. <div class="content-left-top-grid">
  101. <div class="content-left-price-selection">
  102. <h4>Select Price:</h4>
  103. <div class="price-selection-tree">
  104. <span class="col_checkbox">
  105. <input id="10" class="css-checkbox10" type="checkbox">
  106. <label class="normal"><i for="10" name="demo_lbl_10" class="css-label10"> </i> 400</label>
  107. </span>
  108. <span class="col_checkbox">
  109. <input id="11" class="css-checkbox11" type="checkbox">
  110. <label class="active1"><i for="11" name="demo_lbl_11" class="css-label11"> </i>350</label>
  111. </span>
  112. <span class="col_checkbox">
  113. <input id="12" class="css-checkbox12" type="checkbox">
  114. <label class="normal"><i for="12" name="demo_lbl_12" class="css-label12"> </i> 300</label>
  115. </span>
  116. <span class="col_checkbox">
  117. <input id="13" class="css-checkbox13" type="checkbox">
  118. <label class="normal"><i for="13" name="demo_lbl_13" class="css-label13"> </i>250</label>
  119. </span>
  120. <span class="col_checkbox">
  121. <input id="14" class="css-checkbox14" type="checkbox">
  122. <label class="normal"><i for="14" name="demo_lbl_14" class="css-label14"> </i> 200</label>
  123. </span>
  124. <span class="col_checkbox">
  125. <input id="15" class="css-checkbox15" type="checkbox">
  126. <label class="normal"><i for="15" name="demo_lbl_15" class="css-label15"> </i>150</label>
  127. </span>
  128. </div>
  129.  
  130. </div>
  131. </div>
  132.  
  133. </div>
  134. <div class="content-right">
  135. <div class="product-grids">
  136. <!--- start-rate---->
  137. <script src="../Scripts/jstarbox.js"></script>
  138. <link rel="stylesheet" href="../Content/jstarbox.css" type="text/css" media="screen" charset="utf-8" />
  139. <script type="text/javascript">
  140. jQuery(function () {
  141. jQuery('.starbox').each(function () {
  142. var starbox = jQuery(this);
  143. starbox.starbox({
  144. average: starbox.attr('data-start-value'),
  145. changeable: starbox.hasClass('unchangeable') ? false : starbox.hasClass('clickonce') ? 'once' : true,
  146. ghosting: starbox.hasClass('ghosting'),
  147. autoUpdateAverage: starbox.hasClass('autoupdate'),
  148. buttons: starbox.hasClass('smooth') ? false : starbox.attr('data-button-count') || 5,
  149. stars: starbox.attr('data-star-count') || 5
  150. }).bind('starbox-value-changed', function (event, value) {
  151. if (starbox.hasClass('random')) {
  152. var val = Math.random();
  153. starbox.next().text(' ' + val);
  154. return val;
  155. }
  156. })
  157. });
  158. });
  159. </script>
  160. <link href="@Url.Content("~/Content/bootstrap.css")" rel="stylesheet" type="text/css" />
  161. <div class="row">
  162. <div class="col-md-12">
  163. <section id="loginForm">
  164. @Html.AntiForgeryToken()
  165. <hr />
  166. @Html.ValidationSummary(true)
  167. <div class="form1-group">
  168.  
  169. <label class="col-md-2 control-label" for="name">Tên sản phẩm</label>
  170. <div class="col-md-10">
  171. <input class="form-control" id="name" name="name" type="text" value="">
  172. </div>
  173. </div>
  174. <br />
  175. <br />
  176. <div class="form1-group">
  177.  
  178. <label class="col-md-2 control-label" for="price">Giá</label>
  179. <div class="col-md-10">
  180.  
  181. <input class="form-control" id="price" name="price" type="text" value="">
  182. </div>
  183. </div>
  184. <br />
  185. <br />
  186. <div class="form1-group">
  187.  
  188. <label class="col-md-2 control-label" for="noname">Giới tính</label>
  189. <div class="col-md-10">
  190.  
  191. <label>@Html.RadioButton("ABC", "1")Nam</label>
  192. <label>@Html.RadioButton("ABC", "2")Nữ</label>
  193. <label>@Html.RadioButton("ABC", "0",true)Cả hai</label>
  194. </div>
  195. </div>
  196. <br />
  197. <br />
  198. <div class="form-group">
  199. <div class="col-md-offset-2 col-md-10">
  200. <input type="submit" id="btnsearch" value="Tìm kiếm" class="btn btn-default" />
  201. </div>
  202. </div>
  203.  
  204. </section>
  205. </div>
  206.  
  207. <div id="_viewSearchNangCao" style="margin-top: 1.5cm">
  208. @Html.Partial("_viewSearchNangCao", Model)
  209. </div>
  210.  
  211. </div>
  212.  
  213.  
  214.  
  215. <!---//End-rate---->
  216. <!---caption-script---->
  217. <!---//caption-script---->
  218.  
  219. @section searchnangcao{
  220. <script type="text/javascript">
  221. function ChangeUrl(page, url) {
  222. if (typeof (history.pushState) != "undefined") {
  223. var obj = { Page: page, Url: url };
  224. history.pushState(obj, obj.Page, obj.Url);
  225. } else {
  226. alert("Browser does not support HTML5.");
  227. }
  228.  
  229.  
  230. }
  231.  
  232. function search() {
  233. $.ajax({
  234.  
  235. url: "/Home/searchNangCao?name=" + $('#name').val() + "&price=" + $('#price').val() + "&gender=" +$('input:radio[name=ABC]:checked').val()
  236.  
  237. ,
  238. success: function (result) {
  239. ChangeUrl("Index", "/Home/searchNangCao?name=" + $('#name').val() + "&price=" + $('#price').val() + "&gender=" + $('input:radio[name=ABC]:checked').val());
  240. $('#_viewSearchNangCao').html(result);
  241. }
  242. });
  243. }
  244.  
  245.  
  246. $(function () {
  247. $('#btnsearch').click(function () {
  248. search();
  249. });
  250. $('#name').keypress(function (e) {
  251. if (e.keyCode == 13)
  252. search();
  253. });
  254.  
  255. $('body').on('click', '#_viewSearchNangCao .pagination a', function (event) {
  256. event.preventDefault();
  257. console.log('page');
  258.  
  259. var name = $('#name').val();
  260. if (name == undefined || name == '') {
  261. name = '';
  262. } else {
  263. name = '&name=' + name;
  264. }
  265. var price = $('#price').val();
  266. if (price == undefined || price == '') {
  267. price = '';
  268. } else {
  269. price = '&price=' + price;
  270. }
  271. var gender = $('input:radio[name=ABC]:checked').val();
  272. if (gender == undefined || gender == '')
  273. {
  274. gender = "0";
  275. }
  276. else
  277. {
  278.  
  279. gender = '&gender=' + gender;
  280. }
  281.  
  282. var url1 = $(this).attr('href') + "&name=" + $('#name').val() + "&price=" + $('#price').val() + "&gender=" + $('input:radio[name=ABC]:checked').val();
  283. console.log(url1);
  284. $.ajax({
  285. url: url1,
  286. success: function (result) {
  287. ChangeUrl('Index', url1);
  288. $('#_viewSearchNangCao').html(result);
  289. }
  290. });
  291. });
  292. })
  293. </script>
  294. }
  295.  
  296.  
  297.  
  298.  
  299.  
  300. <div class="clear"> </div>
  301. </div>
  302. </div>
  303. <div class="clear"> </div>
  304. </div>
  305. </div>
  306. </body>
  307. </html>
  308. --------------------------------------
  309. Tạo tiếp view mới đặt tên là _viewSearchNangCao
  310. ---------------------------------------
  311. @using PagedList.Mvc
  312. @using PagedList
  313. @model PagedList.IPagedList<MvcApplication2.Models.Product>
  314.  
  315.  
  316. @foreach (var item in Model.Select((model, index) => new { model, index }))
  317. {
  318.  
  319. <div onclick="location.href='/Product/ProductDetails/@Html.DisplayFor(modelItem => item.model.id)';" class="@((item.index+1) % 3 == 0 ? "product-grid last-grid": "product-grid")">
  320. <div class="product-grid-head">
  321. <ul class="grid-social">
  322. <li><a class="facebook" href="#"><span> </span></a></li>
  323. <li><a class="twitter" href="#"><span> </span></a></li>
  324. <li><a class="googlep" href="#"><span> </span></a></li>
  325. <div class="clear"> </div>
  326. </ul>
  327. <div class="block">
  328. <div class="starbox small ghosting"> </div> <span> (46)</span>
  329. </div>
  330. </div>
  331. <div class="product-pic">
  332.  
  333. <a href="/Product/ProductDetails/@Html.DisplayFor(modelItem => item.model.id)"><img src="../images/product2.jpg" title="product-name" /></a>
  334. <p>
  335. <a href="/Product/ProductDetails/@Html.DisplayFor(modelItem => item.model.id)"><small>Nike</small> @Html.DisplayFor(modelItem => item.model.name) <small>Phantom</small> FG</a>
  336. <span>@Html.DisplayFor(modelItem => item.model.status)</span>
  337. </p>
  338. </div>
  339. <div class="product-info">
  340.  
  341. <div class="product-info-cust">
  342. @Html.ActionLink("Details", "ProductDetails", "Product", new { id = item.model.id }, null)
  343. </div>
  344. <div class="product-info-price">
  345.  
  346.  
  347.  
  348. <a href="/Product/ProductDetails/@Html.DisplayFor(modelItem => item.model.id)">&#163; @Html.DisplayFor(modelItem => item.model.price) </a>
  349.  
  350. </div>
  351. <div class="clear"> </div>
  352. </div>
  353. <div class="more-product-info">
  354. <span> </span>
  355. </div>
  356. </div>
  357. }
  358.  
  359.  
  360.  
  361. <div class="clear"> </div>
  362. @Html.PagedListPager(Model, page => Url.Action("searchNangCao","Home", new { page }), PagedListRenderOptions.OnlyShowFivePagesAtATime)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement