MVC 3模型foreach过滤器 [英] MVC 3 model foreach filter
本文介绍了MVC 3模型foreach过滤器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我具有以下剃刀语法
@{
foreach (var p in Model)
{
<b>@p.Age</b>
}
}
我想过滤foreach循环,以便仅查看p.City ="New York"的模型记录.
I would like to filter the foreach loop to only look at the Model records where p.City = "New York"
我的语法是什么样的?
我希望我对此有解释.
谢谢
推荐答案
@foreach (var p in Model.Where(i => i.City == "New York")) {
<b>@p.Age</b>
}
您可能决定在控制器操作中进行此过滤,具体取决于您是否需要其他视图中没有纽约"城市的模型记录.
You might decide to do this filtering in the controller action, depending on whether you need other model records that don't have a city of "New York" in your view or not.
这篇关于MVC 3模型foreach过滤器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文