title: how to "Paginate" results into rows not pages
body: <p>This one is very difficult for me to word, which is what is failing me in my google searching, i brand new to asp.net and it's giving me some difficulties with the logic of this requirement</p>
  
  <p>I have a bunch of results which are displayed primarily as images with some text overlayed.</p>
  
  <p>I have some HTML that is required to show these images, but it uses custom styling to show each "row" of images, it uses div's for a custom look.</p>
  
  <p>What i'm needing to do, is work out a way in the cshtml file display a html block to start a row, and then output the html for 6 of the items, then close off that row and begin another one and rinse repeat until completed, but i cannot for the life of me work out how i would go about that in asp.net.</p>
  
  <p>This might be a very very simple issue, but due to my inability to word this correctly for google, I'm really struggling to find anything online.</p>
  
  <p>The closest visual example i can think of is something like Netflix, but without the ability to scroll the movies, so all the movies are listed in those rows.</p>
  
  <p>i'm currently using the following method, </p>
  
  <pre><code>@foreach (var item in Model)
  {
    html...
  }
  </code></pre>
  
  <p>My original thought was to have a counter and do a conditional statement when the count hit's six, closing the row and starting a new one, but i cannot work out how to mix that much html into code blocks.</p>
  
  <pre><code>@{
   int count = 0;
   foreach(var item in model)
   {
      count++;
      //Output current item's html 
      if(count == 6)
      {
          //End current row, start new row
          count = 0;
      } 
   }
  </code></pre>
  
  <p>but as i mentioned, i can only find how to mix single html elements in with code blocks using the @: method, and i need a block of html.</p>
  
  <p>Adding my controller code as requested, I have it kinda working using viewbag, but the groupedModel seems to split each movie into a separate row.</p>
  
  <pre><code>// GET: Movies
  public ActionResult Index(string movieGenre, string searchString)
  {
      var GenreList = new List&lt;string&gt;();
  
      var GenreQry = from d in db.Movies
                     orderby d.Genre
                     select d.Genre;
  
      GenreList.AddRange(GenreQry.Distinct());
      ViewBag.movieGenre = new SelectList(GenreList);
  
      var movies = from m in db.Movies
                   select m;
  
      if(!String.IsNullOrEmpty(searchString))
      {
          movies = movies.Where(s =&gt; s.Title.Contains(searchString));
      }
  
      if(!string.IsNullOrEmpty(movieGenre))
      {
          movies = movies.Where(x =&gt; x.Genre == movieGenre);
      }
  
      var groupedModel = movies.AsEnumerable().Select((e, i) =&gt; new { Element = e, Index = i }).GroupBy(e =&gt; e.Index % 6).Select(g =&gt; g.Select(e =&gt; e.Element));
      ViewBag.grouped = groupedModel;
  
      return View(movies);
  }
  </code></pre>
  
  <p>and my view (With most of the HTML removed for ease of reading):</p>
  
  <pre><code>@model IEnumerable&lt;MvcMovie.Models.Movie&gt;
  
  @{
      ViewBag.Title = "Index";
  }
  
  &lt;p&gt;
      @Html.ActionLink("Create New", "Create")
  
      @using (Html.BeginForm("Index", "Movies", FormMethod.Get))
      {
          &lt;p&gt;
              Genre: @Html.DropDownList("movieGenre", "All")
              Title: @Html.TextBox("SearchString")
              &lt;input type="submit" value="Filter" /&gt;
          &lt;/p&gt;
      }
  &lt;/p&gt;
  
  @foreach(var group in ViewBag.grouped)
  { 
     &lt;div class="MovieRow"&gt;
         @foreach (var item in group)
         { 
             &lt;div class="bob-title"&gt;@Html.Display((item as MvcMovie.Models.Movie).Title)&lt;/div&gt;
         }
     &lt;/div&gt;
  }
  </code></pre>
  
  <p>EDIT:</p>
  
  <p>The only problem i have left now, is that i can't seem to get the item variables to output, none of the <code>@Html.Display((item as MvcMovie.Models.Movie)</code> sections output anything.</p>