如何在 HTML 页面中显示 foreach 循环中的循环次数
我当前正在尝试计算 ASP.NET MVC 视图中返回的搜索结果数,以显示搜索返回的结果数。
我尝试计算显示搜索结果的 foreach
循环次数。
我还尝试计算随视图返回的模型对象中的项目数:
<% Html.Display(Model.Count().ToString());%>
它从未真正在我的网站上发布任何内容。
有人知道如何解决这个问题吗?
I'm currently trying to count the number of search results returned in my ASP.NET MVC view to display how many results the search gave in return.
I've tried counting the number of loops of the foreach
that displays the search results.
I've also tried counting the number of items in the Model object returned with the view:
<% Html.Display(Model.Count().ToString());%>
it never really posts anything on my site.
Anybody got an idea how to solve this issue?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
了解
foreach
循环进行了多少次迭代的唯一方法是自己包含一个计数器:要在
.aspx
视图中显示,然后使用:或在 Razor 中:
如果这样不适合你,那么还有其他因素在起作用。你能展示一个简短的工作示例吗?
The only way to know how many iterations a
foreach
loop has taken is to include a counter yourself:To display in a
.aspx
view then use:or in Razor:
If this isn't working for you, then some other factor is at play. Can you show a short working example where it doesn't work?
或许
Maybe