How can i display for each page 20 records Just like asp.net gridview Pagesize="20" property,
In the same way i want to display 20 records for each page in MVC4?
How can i do this?
@using PagedList
@using PagedList.Mvc
@model IEnumerable<Hoda.Models.demoproduct>
@{
ViewBag.Title = "Neww products";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<p>
<a href="~/Addnew/Create" class="btn btn-primary" style="text-align:center">Add New Car</a>
@using (Html.BeginForm("Index", "Addnew", FormMethod.Get))
{
<b>Search by</b>
@Html.RadioButton("searchBy", "TagNo", true)<text>Tagno</text>
@Html.RadioButton("searchBy", "StockNo", true)<text>StockNo</text>
<br />
@Html.TextBox("search")<input type="submit" value="Search" />
}
</p>
<table class="table table-striped" style="width:auto">
<tr>
<th>
@Html.DisplayNameFor(model => model.TagNo)
</th>
<th>
@Html.DisplayNameFor(model => model.StockNo)
</th>
<th>
@Html.DisplayNameFor(model => model.ProductName)
</th>
<th>
@Html.DisplayNameFor(model => model.Specifications)
</th>
<th>
@Html.DisplayNameFor(model => model.Quality_ValueAnalysis)
</th>
<th>
@Html.DisplayNameFor(model => model.Aboutus)
</th>
<th>
@Html.DisplayNameFor(model => model.Price)
</th>
</tr>
@if (Model.Count() == 0)
{
<tr>
<td colspan="4">No rows match for this search</td>
</tr>
}
else
{
foreach (var item in Model)
{
<tr>
<td>
@Html.DisplayFor(modelItem => item.TagNo)
</td>
<td>
@Html.DisplayFor(modelItem => item.StockNo)
</td>
<td>
@Html.DisplayFor(modelItem => item.ProductName)
</td>
<td>
@Html.Raw(item.Specifications)
</td>
<td>
@Html.Raw(item.Quality_ValueAnalysis)
</td>
<td>
@Html.Raw(item.Aboutus)
</td>
<td>
@Html.DisplayFor(modelItem => item.Price)
</td>
<td>
<td>
@Html.ActionLink("Edit", "Edit", new { id = item.TagNo })
@Html.ActionLink("Details", "Newcars", new { id = item.TagNo })
</td>
</tr>
}
}
</table>
public ActionResult Index(string searchBy, string search)
{
if (searchBy == "TagNo")
{
return View(db.demoproducts.Where(x => x.TagNo == search || search == null).ToList());
}
else
{
return View(db.demoproducts.Where(x => x.StockNo.StartsWith(search) || search == null).ToList());
}
}
This is my actual code,
I want paging How can i do?