0

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>

2 Answers 2

2
@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>
}
Sign up to request clarification or add additional context in comments.

1 Comment

I've provided a concise answer, but this one works too. +1
1

Like this:

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

1 Comment

Yep, no difference:)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.