Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Layout
- ----------
- @RenderSection("searchnangcao", required: false)
- ------------
- controller
- ------------
- public ActionResult searchNangCao (int? page, string name, string price, string gender)
- {
- int _gender = Convert.ToInt32(gender);
- int _price = 100000;
- if(!String.IsNullOrEmpty(price) && Convert.ToInt32(price)!=null)
- {
- _price = Convert.ToInt32(price);
- }
- string _name = name;
- int pageSize = 3;
- int numpage = (page ?? 1);
- var product = ssde.Products.AsQueryable();
- int temp = 0;
- if (_gender == 0)
- {
- if (!String.IsNullOrEmpty(name) || !String.IsNullOrEmpty(price))
- {
- if (String.IsNullOrEmpty(name))
- {
- product = ssde.Products.Where(p => p.price < _price).OrderBy(p => p.id);
- }
- else
- {
- if (String.IsNullOrEmpty(price))
- {
- product = ssde.Products.Where(p => p.name.ToLower().Contains(name.ToLower())).OrderBy(p => p.id);
- }
- else
- {
- product = ssde.Products.Where(p => p.name.ToLower().Contains(name.ToLower()) && p.price < _price).OrderBy(x => x.id);
- }
- }
- temp = 1;
- }
- }
- else
- {
- if (String.IsNullOrEmpty(name))
- {
- product = ssde.Products.Where(p => p.price < _price && p.id_gender == _gender).OrderBy(p => p.id);
- }
- else
- {
- if (String.IsNullOrEmpty(price))
- {
- product = ssde.Products.Where(p => p.name.ToLower().Contains(name.ToLower())&& p.id_gender == _gender).OrderBy(p => p.id);
- }
- else
- {
- product = ssde.Products.Where(p => p.name.ToLower().Contains(name.ToLower()) && p.price < _price&& p.id_gender == _gender).OrderBy(x => x.id);
- }
- }
- temp = 1;
- }
- ViewBag.temp = temp;
- if(temp == 0)
- {
- product = product.OrderBy(x => x.id);
- }
- return Request.IsAjaxRequest()
- ? (ActionResult)PartialView("_viewSearchNangCao", product.ToPagedList(numpage, pageSize))
- : View(product.ToPagedList(numpage,pageSize));
- }
- ----------------------------------------
- tạo view mới tên là searchNangCao
- --------------------------------------
- @using MvcApplication2.Models
- @model PagedList.IPagedList<MvcApplication2.Models.Product>
- @using PagedList;
- @using PagedList.Mvc;
- @{
- ViewBag.Title = "Search";
- Layout = "~/Views/Shared/_Layout.cshtml";
- }
- <html>
- <body>
- <div class="clear"> </div>
- <!----//End-image-slider---->
- <!----start-price-rage--->
- <div class="wrap">
- </div>
- <!----//End-price-rage--->
- <!--- start-content---->
- <div class="content">
- <div class="wrap">
- <div class="content-left">
- <div class="content-left-top-grid">
- <div class="content-left-price-selection">
- <h4>Select Price:</h4>
- <div class="price-selection-tree">
- <span class="col_checkbox">
- <input id="10" class="css-checkbox10" type="checkbox">
- <label class="normal"><i for="10" name="demo_lbl_10" class="css-label10"> </i> 400</label>
- </span>
- <span class="col_checkbox">
- <input id="11" class="css-checkbox11" type="checkbox">
- <label class="active1"><i for="11" name="demo_lbl_11" class="css-label11"> </i>350</label>
- </span>
- <span class="col_checkbox">
- <input id="12" class="css-checkbox12" type="checkbox">
- <label class="normal"><i for="12" name="demo_lbl_12" class="css-label12"> </i> 300</label>
- </span>
- <span class="col_checkbox">
- <input id="13" class="css-checkbox13" type="checkbox">
- <label class="normal"><i for="13" name="demo_lbl_13" class="css-label13"> </i>250</label>
- </span>
- <span class="col_checkbox">
- <input id="14" class="css-checkbox14" type="checkbox">
- <label class="normal"><i for="14" name="demo_lbl_14" class="css-label14"> </i> 200</label>
- </span>
- <span class="col_checkbox">
- <input id="15" class="css-checkbox15" type="checkbox">
- <label class="normal"><i for="15" name="demo_lbl_15" class="css-label15"> </i>150</label>
- </span>
- </div>
- </div>
- </div>
- </div>
- <div class="content-right">
- <div class="product-grids">
- <!--- start-rate---->
- <script src="../Scripts/jstarbox.js"></script>
- <link rel="stylesheet" href="../Content/jstarbox.css" type="text/css" media="screen" charset="utf-8" />
- <script type="text/javascript">
- jQuery(function () {
- jQuery('.starbox').each(function () {
- var starbox = jQuery(this);
- starbox.starbox({
- average: starbox.attr('data-start-value'),
- changeable: starbox.hasClass('unchangeable') ? false : starbox.hasClass('clickonce') ? 'once' : true,
- ghosting: starbox.hasClass('ghosting'),
- autoUpdateAverage: starbox.hasClass('autoupdate'),
- buttons: starbox.hasClass('smooth') ? false : starbox.attr('data-button-count') || 5,
- stars: starbox.attr('data-star-count') || 5
- }).bind('starbox-value-changed', function (event, value) {
- if (starbox.hasClass('random')) {
- var val = Math.random();
- starbox.next().text(' ' + val);
- return val;
- }
- })
- });
- });
- </script>
- <link href="@Url.Content("~/Content/bootstrap.css")" rel="stylesheet" type="text/css" />
- <div class="row">
- <div class="col-md-12">
- <section id="loginForm">
- @Html.AntiForgeryToken()
- <hr />
- @Html.ValidationSummary(true)
- <div class="form1-group">
- <label class="col-md-2 control-label" for="name">Tên sản phẩm</label>
- <div class="col-md-10">
- <input class="form-control" id="name" name="name" type="text" value="">
- </div>
- </div>
- <br />
- <br />
- <div class="form1-group">
- <label class="col-md-2 control-label" for="price">Giá</label>
- <div class="col-md-10">
- <input class="form-control" id="price" name="price" type="text" value="">
- </div>
- </div>
- <br />
- <br />
- <div class="form1-group">
- <label class="col-md-2 control-label" for="noname">Giới tính</label>
- <div class="col-md-10">
- <label>@Html.RadioButton("ABC", "1")Nam</label>
- <label>@Html.RadioButton("ABC", "2")Nữ</label>
- <label>@Html.RadioButton("ABC", "0",true)Cả hai</label>
- </div>
- </div>
- <br />
- <br />
- <div class="form-group">
- <div class="col-md-offset-2 col-md-10">
- <input type="submit" id="btnsearch" value="Tìm kiếm" class="btn btn-default" />
- </div>
- </div>
- </section>
- </div>
- <div id="_viewSearchNangCao" style="margin-top: 1.5cm">
- @Html.Partial("_viewSearchNangCao", Model)
- </div>
- </div>
- <!---//End-rate---->
- <!---caption-script---->
- <!---//caption-script---->
- @section searchnangcao{
- <script type="text/javascript">
- function ChangeUrl(page, url) {
- if (typeof (history.pushState) != "undefined") {
- var obj = { Page: page, Url: url };
- history.pushState(obj, obj.Page, obj.Url);
- } else {
- alert("Browser does not support HTML5.");
- }
- }
- function search() {
- $.ajax({
- url: "/Home/searchNangCao?name=" + $('#name').val() + "&price=" + $('#price').val() + "&gender=" +$('input:radio[name=ABC]:checked').val()
- ,
- success: function (result) {
- ChangeUrl("Index", "/Home/searchNangCao?name=" + $('#name').val() + "&price=" + $('#price').val() + "&gender=" + $('input:radio[name=ABC]:checked').val());
- $('#_viewSearchNangCao').html(result);
- }
- });
- }
- $(function () {
- $('#btnsearch').click(function () {
- search();
- });
- $('#name').keypress(function (e) {
- if (e.keyCode == 13)
- search();
- });
- $('body').on('click', '#_viewSearchNangCao .pagination a', function (event) {
- event.preventDefault();
- console.log('page');
- var name = $('#name').val();
- if (name == undefined || name == '') {
- name = '';
- } else {
- name = '&name=' + name;
- }
- var price = $('#price').val();
- if (price == undefined || price == '') {
- price = '';
- } else {
- price = '&price=' + price;
- }
- var gender = $('input:radio[name=ABC]:checked').val();
- if (gender == undefined || gender == '')
- {
- gender = "0";
- }
- else
- {
- gender = '&gender=' + gender;
- }
- var url1 = $(this).attr('href') + "&name=" + $('#name').val() + "&price=" + $('#price').val() + "&gender=" + $('input:radio[name=ABC]:checked').val();
- console.log(url1);
- $.ajax({
- url: url1,
- success: function (result) {
- ChangeUrl('Index', url1);
- $('#_viewSearchNangCao').html(result);
- }
- });
- });
- })
- </script>
- }
- <div class="clear"> </div>
- </div>
- </div>
- <div class="clear"> </div>
- </div>
- </div>
- </body>
- </html>
- --------------------------------------
- Tạo tiếp view mới đặt tên là _viewSearchNangCao
- ---------------------------------------
- @using PagedList.Mvc
- @using PagedList
- @model PagedList.IPagedList<MvcApplication2.Models.Product>
- @foreach (var item in Model.Select((model, index) => new { model, index }))
- {
- <div onclick="location.href='/Product/ProductDetails/@Html.DisplayFor(modelItem => item.model.id)';" class="@((item.index+1) % 3 == 0 ? "product-grid last-grid": "product-grid")">
- <div class="product-grid-head">
- <ul class="grid-social">
- <li><a class="facebook" href="#"><span> </span></a></li>
- <li><a class="twitter" href="#"><span> </span></a></li>
- <li><a class="googlep" href="#"><span> </span></a></li>
- <div class="clear"> </div>
- </ul>
- <div class="block">
- <div class="starbox small ghosting"> </div> <span> (46)</span>
- </div>
- </div>
- <div class="product-pic">
- <a href="/Product/ProductDetails/@Html.DisplayFor(modelItem => item.model.id)"><img src="../images/product2.jpg" title="product-name" /></a>
- <p>
- <a href="/Product/ProductDetails/@Html.DisplayFor(modelItem => item.model.id)"><small>Nike</small> @Html.DisplayFor(modelItem => item.model.name) <small>Phantom</small> FG</a>
- <span>@Html.DisplayFor(modelItem => item.model.status)</span>
- </p>
- </div>
- <div class="product-info">
- <div class="product-info-cust">
- @Html.ActionLink("Details", "ProductDetails", "Product", new { id = item.model.id }, null)
- </div>
- <div class="product-info-price">
- <a href="/Product/ProductDetails/@Html.DisplayFor(modelItem => item.model.id)">£ @Html.DisplayFor(modelItem => item.model.price) </a>
- </div>
- <div class="clear"> </div>
- </div>
- <div class="more-product-info">
- <span> </span>
- </div>
- </div>
- }
- <div class="clear"> </div>
- @Html.PagedListPager(Model, page => Url.Action("searchNangCao","Home", new { page }), PagedListRenderOptions.OnlyShowFivePagesAtATime)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement