ASPForums.Net RSS Feedhttp://www.aspforums.net/Handlers/RSS.ashxLatest additions to the content that appears on ASPForums.Net(c) 2019 www.aspforums.com. All rights reserved.Implement Filtering and Paging using PagedList Pager in ASP.Net MVC<p>Hi&nbsp;nauna,</p> <p>There is no need to write if else condition to know what is selected.</p> <p>You just need to pass the filter data with ViewBag.</p> <p>Check this example. Now please take its reference and correct your code.</p> <p><span style="text-decoration: underline;"><strong>Database</strong></span></p> <p>For this example I have used of Northwind database that you can download using the link given below.</p> <p><a href="https://www.aspsnippets.com/Articles/Install-Microsoft-Northwind-and-Pubs-Sample-databases-in-SQL-Server-Management-Studio.aspx" target="_blank">Download Northwind Database</a></p> <p><strong><span style="text-decoration: underline;">Model </span></strong></p> <pre class="brush: csharp">public class CustomerModel { public string Id { get; set; } public string Name { get; set; } public string City { get; set; } public string Country { get; set; } public List&lt;CustomerModel&gt; Customers { get; set; } }</pre> <p><strong><span style="text-decoration: underline;">Controller</span></strong></p> <pre class="brush: csharp">public class HomeController : Controller { [HttpGet] public ActionResult Index(int? page, string city = &#34;&#34;, string country = &#34;&#34;) { ViewBag.Country = country; ViewBag.City = city; int pageSize = 5; int pageIndex = page.HasValue ? Convert.ToInt32(page) : 1; List&lt;CustomerModel&gt; customers = (new NorthwindEntities()).Customers .Where(x =&gt; x.City.Contains(city) &amp;&amp; x.Country.Contains(country)) .Select(x =&gt; new CustomerModel { Id = x.CustomerID, Name = x.ContactName, City = x.City, Country = x.Country }).ToList(); CustomerModel customer = new CustomerModel(); customer.Customers = customers; return View(customers.ToPagedList(pageIndex, pageSize)); } }</pre> <p>&nbsp;</p> <pre class="brush: html">@using PagedList @using PagedList.Mvc @using _PagedListPager_MVC.Models @model IPagedList&lt;CustomerModel&gt; @{ Layout = null; } &lt;!DOCTYPE html&gt; &lt;html&gt; &lt;head&gt; &lt;meta name=&#34;viewport&#34; content=&#34;width=device-width&#34; /&gt; &lt;title&gt;PagedList Paging MVC&lt;/title&gt; &lt;style&gt; .ul.pagination { display: inline-block; padding: 0; margin: 0; } ul.pagination li { display: inline; } ul.pagination li a { border: 1px solid #ccc; color: black; float: left; padding: 8px 16px; text-decoration: none; transition: background-color .3s; } ul.pagination li a.active { } ul.pagination li a:hover:not(.active) { background-color: #ddd; } &lt;/style&gt; &lt;/head&gt; &lt;body&gt; @using (Html.BeginForm(&#34;Index&#34;, &#34;Home&#34;, FormMethod.Get)) { &lt;table&gt; &lt;tr&gt; &lt;td&gt;City&lt;/td&gt; &lt;td&gt;&lt;input type=&#34;text&#34; name=&#34;city&#34; value=&#34;@ViewBag.City&#34; /&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;Country&lt;/td&gt; &lt;td&gt;&lt;input type=&#34;text&#34; name=&#34;country&#34; value=&#34;@ViewBag.Country&#34; /&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td colspan=&#34;2&#34;&gt;&lt;input type=&#34;submit&#34; value=&#34;Search&#34; /&gt;&lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;table&gt; &lt;tr&gt; &lt;th&gt;@Html.Label(&#34;ID&#34;)&lt;/th&gt; &lt;th&gt;@Html.Label(&#34;Name&#34;)&lt;/th&gt; &lt;th&gt;@Html.Label(&#34;City&#34;)&lt;/th&gt; &lt;th&gt;@Html.Label(&#34;Country&#34;)&lt;/th&gt; &lt;/tr&gt; @foreach (var item in Model) { &lt;tr&gt; &lt;td&gt;@item.Id&lt;/td&gt; &lt;td&gt;@item.Name&lt;/td&gt; &lt;td&gt;@item.City&lt;/td&gt; &lt;td&gt;@item.Country&lt;/td&gt; &lt;/tr&gt; } &lt;/table&gt; &lt;div class=&#34;pagination&#34;&gt; Page @(Model.PageCount &lt; Model.PageNumber ? 0 : Model.PageNumber) of @Model.PageCount @Html.PagedListPager(Model, page =&gt; Url.Action(&#34;Index&#34;, new { Country = ViewBag.Country, City = ViewBag.City, page }), PagedListRenderOptions.PageNumbersOnly) &lt;/div&gt; } &lt;/body&gt; &lt;/html&gt; </pre> <p>&nbsp;</p>https://www.aspforums.net:443/Threads/928451/Implement-Filtering-and-Paging-using-PagedList-Pager-in-ASPNet-MVC/https://www.aspforums.net:443/Threads/928451/Implement-Filtering-and-Paging-using-PagedList-Pager-in-ASPNet-MVC/Sun, 30 Jun 2019 01:31:44 GMT