我在Visual Studios,MVC 3,Razor引擎中创建新闻传送项目,我试图只显示一次,比如说10个提要数量。在index.cshtml中只显示x个项目数量
目前而我得到的数据库会我用这个index.cshtml:
@model IEnumerable
@{
ViewBag.Title = "NewsFeed";
}
@ViewBag.Message
@foreach (var item in Model)
{
@Html.ActionLink(item.Name, "Edit", new { id=item.Id })
@item.Subject, @item.Created
@Html.Raw(item.Content.Replace(Environment.NewLine, "
"))
}
在foreach需要每一个项目,我想知道如果我可以使用一个for循环或类似只显示东西10个最新的Feed。
在此先感谢。
2013-03-12
Mappan
+2
'@foreach(VAR在Model.OrderByDescending(项x => x.Created)。取(10))' –
2013-03-12 16:14:29
+1
限制列表_in的Controler_。 –
2013-03-12 16:16:09
+0
@IliaG谢谢,labda表达式会照顾它。 –
2013-03-12 16:19:13