Search code examples
asp.net-mvcienumerable

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>

Solution

  • @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>
    }