Answered by:
How to display current record and total records in textbox MVC, JQuery

Question
-
User1118469561 posted
I would like to display current record and total record in a textbox in MVC project. I also uploaded images for better understanding for the stack team.
Friday, July 10, 2020 6:19 AM
Answers
-
User1686398519 posted
Hi Nadeem M Taj,
According to your description and image, I make a small demo by PageList.
You can customize the style application according to your needs.
More detail steps you can refer this link
Model
public class Student { public int id { get; set; } public string FirstName { get; set; } public string LastName { get; set; } public string Gener { get; set; } public int Age { get; set; } }
Controller
public ActionResult Index(int? page) { int pageSize = 5; int pageNumber = (page ?? 1); var students = from s in db.Students select s ; students = students.OrderBy(s => s.id); return View(students.ToPagedList(pageNumber,pageSize)); }
View
@model PagedList.IPagedList<pageList.Models.Student> @using PagedList.Mvc <link href="~/Content/PagedList.css" rel="stylesheet" type="text/css" /> @{ ViewBag.Title = "Index"; } <h2>Index</h2> <p> @Html.ActionLink("Create New", "Create") </p> <table class="table"> <tr> <th> <b>First Name</b> </th> <th> <b>Last Name</b> </th> <th> <b>Gener</b> </th> <th> <b>Age</b> </th> <th></th> </tr> @foreach (var item in Model) { <tr> <td> @Html.DisplayFor(modelItem => item.FirstName) </td> <td> @Html.DisplayFor(modelItem => item.LastName) </td> <td> @Html.DisplayFor(modelItem => item.Gener) </td> <td> @Html.DisplayFor(modelItem => item.Age) </td> <td> @Html.ActionLink("Edit", "Edit", new { id=item.id }) | @Html.ActionLink("Details", "Details", new { id=item.id }) | @Html.ActionLink("Delete", "Delete", new { id=item.id }) </td> </tr> } </table> <div id="container"> <textbox> @(Model.PageCount<Model.PageNumber?0:Model.PageNumber) of @Model.PageCount </textbox> @Html.PagedListPager(Model, page => Url.Action("Index", new {page} )) </div>
Best regards,
Yihui Sun
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Tuesday, July 14, 2020 10:34 AM
All replies
-
User348806598 posted
Hi,
You can try running this from repo-
https://github.com/anupdg/mvcsamples/blob/master/Views/ServerSidePaging/Index.cshtml
Saturday, July 11, 2020 3:39 PM -
User1686398519 posted
Hi Nadeem M Taj,
According to your description and image, I make a small demo by PageList.
You can customize the style application according to your needs.
More detail steps you can refer this link
Model
public class Student { public int id { get; set; } public string FirstName { get; set; } public string LastName { get; set; } public string Gener { get; set; } public int Age { get; set; } }
Controller
public ActionResult Index(int? page) { int pageSize = 5; int pageNumber = (page ?? 1); var students = from s in db.Students select s ; students = students.OrderBy(s => s.id); return View(students.ToPagedList(pageNumber,pageSize)); }
View
@model PagedList.IPagedList<pageList.Models.Student> @using PagedList.Mvc <link href="~/Content/PagedList.css" rel="stylesheet" type="text/css" /> @{ ViewBag.Title = "Index"; } <h2>Index</h2> <p> @Html.ActionLink("Create New", "Create") </p> <table class="table"> <tr> <th> <b>First Name</b> </th> <th> <b>Last Name</b> </th> <th> <b>Gener</b> </th> <th> <b>Age</b> </th> <th></th> </tr> @foreach (var item in Model) { <tr> <td> @Html.DisplayFor(modelItem => item.FirstName) </td> <td> @Html.DisplayFor(modelItem => item.LastName) </td> <td> @Html.DisplayFor(modelItem => item.Gener) </td> <td> @Html.DisplayFor(modelItem => item.Age) </td> <td> @Html.ActionLink("Edit", "Edit", new { id=item.id }) | @Html.ActionLink("Details", "Details", new { id=item.id }) | @Html.ActionLink("Delete", "Delete", new { id=item.id }) </td> </tr> } </table> <div id="container"> <textbox> @(Model.PageCount<Model.PageNumber?0:Model.PageNumber) of @Model.PageCount </textbox> @Html.PagedListPager(Model, page => Url.Action("Index", new {page} )) </div>
Best regards,
Yihui Sun
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Tuesday, July 14, 2020 10:34 AM -
User1118469561 posted
Appreciated and thanks alot.
Thursday, July 30, 2020 6:48 AM