I'm drawing a blank on this. I have two foreach loops that are creating div's and I'm trying to get 1 or two items from the 2nd foreach to display every 2 items from the first foreach.... here's the code..

@foreach (var stream in Model.LiveStreams)
{
    <div id="divLiveStream" class="well-livestream well-sm">
       <div class="row">
          <div class="col-md-2">
              <div class="ui-icon-image">
                  <img src="~/Images/placeholder.jpg" width="100%" />
              </div>
          </div>
          <div class="col-md-10">
              <div class="text-left row">
                  <div class="col-md-12">
                         @stream.UserName
                  </div>
                  <div class="col-md-12">
                         @stream.Status
                   </div>
              </div>
          </div>
       </div>
    </div>
}
@foreach (var post in Model.LivePosts)
{
   <div id="divLivePost" class="well-liveposts well-sm">
     <div class="row">
          <div class="col-md-2">
              <div class="ui-icon-image">
                  <img src="~/Images/placeholder.jpg" width="100%" />
              </div>
          </div>
          <div class="col-md-10">
              <div class="text-left row">
                  <div class="col-md-12">
                       @post.AspNetUser.UserName
                  </div>
                  <div class="col-md-12">
                       @post.PostDescription
                  </div>
              </div>
         </div>
     </div>
  </div>
}

So for further clarification, I'm trying to display 2 divLiveStreams, then display 2 divLivePost, and continue on with that pattern. I'm new to MVC so I'm not sure how to go about this and I'm drawing all kinds of blanks on this Friday.. Thanks in advance!

Edit: Here is my ViewModel.

public class LiveStreamViewModel
{
    public IEnumerable<LiveStream> LiveStreams { get; set; }

    public IEnumerable<tPost> LivePosts { get; set; }
}

Related posts

Recent Viewed