Home > Software design >  Show total items cshtml MVC C#
Show total items cshtml MVC C#

Time:05-26

How show count items results in index cshtml, have a paginatedlist guide microsoft mvc

count results in query

var totalregistros= _context.users.Tolist()
return view(totalregistros)

the problem return in view have a pagination

return View(await PaginatedList<users>.CreateAsync(students.AsNoTracking(), pageNumber ?? 1, pageSize));

i need example that show

enter image description here

i need this

enter image description here

CodePudding user response:

Add a TotalItems or similar int property to your PaginatedList class, populate it with the count, and then display that. Additionally, the tutorial from Microsoft shows how to add page counts:

https://docs.microsoft.com/en-us/aspnet/core/data/ef-mvc/sort-filter-page?view=aspnetcore-5.0#add-paging-to-students-index

Also, you are returning a List<users> to your view as the view model. Don't do that. Return a view model that has all of the properties that you want to display, including total count, etc.

  • Related