How can I implement specific list in Asp.net MVC with IEnumerable

I have a problem about list some specific values in list which comes from IEnumerable.

I want to get only first 8 values and first 4 values are listed in first div area and others are listed another div area.

Here is the model list from IEnumerable

@model IEnumerable<ArgedanWebsite.Models.Model.Services>

How can I show values like title and information of Services like @Model.title and @Model.Information?

Here is my div template

<div class="container">
   <div class="row">
        @for (int i = 0; i < 4; ++i){
        <p> </p>
        }
   </div>
</div>

<div class="container">
   <div class="row">
       @for (int i = 4; i < 8; ++i){
        <p> </p>
       }
   </div>
</div>

Upvotes: 0

Views: 39

Answers (2)

Tawab Wakil
Tawab Wakil

Reputation: 2313

Like this:

@for (int i = 0; i < 4; ++i){
    <p>@Model.ElementAt(i).title</p>
}

Upvotes: 1

feihoa
feihoa

Reputation: 517

@foreach (var item in Model.Take(4)) 
{
  <p>@item.title</p>
}

and then

@foreach (var item in Model.Skip(4).Take(4)) 
{
  <p>@item.Information</p>
}

Upvotes: 2

Related Questions