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

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -