Jump to content
TNC-TR
Sign in to follow this  
ratapan

Mvc Cf Ef Sayfalama Ve Filtreleme?

Recommended Posts

Mvc CF EF sayfalama ve filtreleme?

Arkadaşlar uğraştığım projede veritabanından gelen verileri kullanıcının istediği şartlara göre listeliyorum fakat kayıtlar tek sayfada çıkıyor ben sayfalara bölmek istiyorum fakat PagedList olayını bir türlü ekleyemedim projeye.
Controller
 

Model1 db = new Model1();

public ActionResult Sirkuler(string yil, string tipler, string kelime)
        {
            ViewBag.yil = db.sirkuler.Where(x => x.tarih.Contains(yil)).Where(x => x.tip.ToString().Contains(tipler)).Where(x => x.icerik.Contains(kelime)).OrderBy(x=>x.tarih).ToList();
            ViewBag.tip = db.Tipler.ToList();


            return View();
        }

Model
 


{
    [Table("sirkuler")]
    public partial class sirkuler
    {
        public int id { get; set; }

        [Required]
        [StringLength(20)]
        public string numara { get; set; }

        public int tip { get; set; }

        [Required]
        [StringLength(20)]
        public string tarih { get; set; }

        [Required]
        [StringLength(100)]
        public string sirku { get; set; }

        [Column(TypeName = "ntext")]
        [Required]
        public string icerik { get; set; }

        [Column(TypeName = "ntext")]
        public string resimyol { get; set; }

        public virtual Tipler Tipler { get; set; }
    }
}

View
 

@{
    /**/

    ViewBag.Title = "Sirkule";
}
@using boraden1
@model sirkuler

<div class="container bodyContainer">

    <div class="col-xs-12 pgContent">
        <div class="row">
            <div class="col-sm-6">
                <div class="">
                    <p><strong>Arama</strong></p>
                    <select name="tipler" id="tipler" class="form-control">
                        <option value="">Tüm Sirküler</option>
                        @foreach (Tipler tip in ViewBag.tip)
                        {
                            <option value="@tip.id">@tip.tipadi</option>
                        }

                    </select>
                    <input name="kelime" value="" type="text" id="Kelime" class="form-control" placeholder="Aranan Kelime">
                    <select name="yil" id="yil" class="form-control">
                        <option selected="selected" value="">Tüm Yıllar</option>
                        <option value="2018">2018</option>
                        <option value="2017">2017</option>
                        <option value="2016">2016</option>
                        <option value="2015">2015</option>
                        <option value="2014">2014</option>
                        <option value="2013">2013</option>
                        <option value="2012">2012</option>
                        <option value="2011">2011</option>
                        <option value="2010">2010</option>
                        <option value="2009">2009</option>
                        <option value="2008">2008</option>
                        <option value="2007">2007</option>
                        <option value="2006">2006</option>
                        <option value="2005">2005</option>
                        <option value="2004">2004</option>
                        <option value="2003">2003</option>
                        <option value="2002">2002</option>
                        <option value="2001">2001</option>
                    </select>
                    <button type="button" onclick="sirkulergetir(); return false;" class="btn btn-primary" data-loading-text="<i class='fa fa-spinner fa-spin '></i> Aranıyor" id="btnAra">Ara</button>
                </div>
            </div>
        </div>
        <hr />

        <div class="col-xs-12">


            <h2>
                <span id="Baslik">Sirküler</span>
            </h2>
            <table class="table table-hover" cellspacing="0" border="0" id="Sirkulerler" style="border-width:0px;border-collapse:collapse;">
                <thead>

                    <tr>
                        <th scope="col" style="width:160px;">Sirküler Tipi</th>
                        <th scope="col" style="width:90px;">Numara</th>
                        <th scope="col">Sirküler</th>
                        <th scope="col">Tarih</th>


                    </tr>
                </thead>
                <tbody>


                    @foreach (sirkuler yil in ViewBag.yil)
                    {
                        <tr>

                            <td>
                                <span id="ctl00_ctl00_plBody_plBody_DGSirkulerler_ctl03_LblSirkulerTip">@yil.Tipler.tipadi </span>
                            </td>
                            <td>
                                <span id="ctl00_ctl00_plBody_plBody_DGSirkulerler_ctl03_LblNumara" class="txtDarkBlue">@yil.numara</span>
                            </td>
                            <td>
                                <a onclick="return dhExternalLinkRedirect(this)" href="/ExternalLinkRedirect?url=/Home/[email protected]" data-href="/Home/[email protected]" >@yil.sirku</a>
                            </td>
                            <td>
                                <span id="ctl00_ctl00_plBody_plBody_DGSirkulerler_ctl03_LblTarih">(@yil.tarih)</span>
                            </td>

                        </tr>




                    }

                </tbody>
            </table>
            <div class="row">
                <div class="col-md-8 text-center">
                    <div class="pagedList pagination-centered">
                        @Html.PagedListPager(Model, Sayfa =>Url.Action("Sirkule", new {tipler,yil,kelime Sayfa}))
                    </div>
                </div>
            </div>

        </div>
    </div>
</div>

Arkadaşlar sayfalama ve filtreleme işlemini nasıl yapabilirim acaba?

Share this post


Link to post
Share on other sites

Selam,

Filtreleme ve sayfalama işlemleri için biraz uğraşmak lazım işin içine her türlü JavaScript Ajax vs girecek bunu yapan eklentiler zaten var:

Bütün istediklerini yapan https://datatables.net/ ve https://archive.codeplex.com/?p=gridmvc eklentilerini kolayca kullanabilirsin.

Kolay gelsin.

 

  • Thanks 1

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×