c# - Only display 10 items in foreach statement -
i have following razor code in application. how can have 10 items model. once has done following bit of code 10 items in model stops
@foreach (var item in this.model.leaderboard) { <tr> <td>@html.displayfor(modelitem => item.username)</td> <td> @html.displayfor(modelitem => item.score)</td> </tr> }
you can use take()
method of linq.
@foreach (var item in this.model.leaderboard.take(10)) { <tr> <td>@html.displayfor(modelitem => item.username)</td> <td> @html.displayfor(modelitem => item.score)</td> </tr> }
as henk holterman suggested, if don't need whole collection, should limit collection created, not inside view.
msdn reference here.
Comments
Post a Comment