I am trying to count records returned from a search query.
The problem is that I am using the Model Count with paging. It will not display the Model Count for records not on the first page of the returned search query.
The code I am using:
@String.Format("Total of {0} results", Model.Count()) @ViewBag.CurrentFilter
Model count ()) used for the counting of files
@ViewBag.CurrentFilter is used for the name of the search query
Below is the code for the controler
int pageSize = 4;
int pageNumber = (page ?? 1);
var carsviewd = cars.ToPagedList(pageNumber, pageSize);
if (carsviewd.Any())
{
return View(carsviewd);
}
return RedirectToAction("NoResult");
}
}
In controller before return view,you can use:
ViewBag.Count = cars.Count();
then in the View you can use the following:
@String.Format("Total of {0} results", ViewBag.Count)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With