gpt4 book ai didi

asp.net-mvc-3 - 统计并分页显示记录

转载 作者:行者123 更新时间:2023-12-02 09:23:17 25 4
gpt4 key购买 nike

我正在尝试计算从搜索查询返回的记录数。

问题是我将模型计数与分页一起使用。对于不在返回的搜索查询的第一页上的记录,它不会显示模型计数。

我正在使用的代码:

 @String.Format("Total of {0} results", Model.Count()) @ViewBag.CurrentFilter

用于文件计数的模型count())

@ViewBag.CurrentFilter 用于搜索查询的名称

下面是 Controller 的代码

            int pageSize = 4;
int pageNumber = (page ?? 1);

var carsviewd = cars.ToPagedList(pageNumber, pageSize);
if (carsviewd.Any())
{
return View(carsviewd);
}
return RedirectToAction("NoResult");
}


}

最佳答案

在返回 View 之前的 Controller 中,您可以使用:

ViewBag.Count =  cars.Count();

然后在View中你可以使用以下内容:

@String.Format("Total of {0} results", ViewBag.Count)

关于asp.net-mvc-3 - 统计并分页显示记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8828787/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com