title: Display a view with many to many relationship
body: <p>Having problem to display a generic list with books and its authors at view state.
  A book can have one, two or three authors.</p>
  
  <p>How shall I display a list that contains many books with right authors in view level?</p>
  
  <p>// Fullmetalboy</p>
  
  <p>The following tables of the database is:</p>
  
  <p>Bok (eng. Book)</p>
  
  <ul>
  <li>BokID</li>
  <li>Titel</li>
  <li>Styckpris </li>
  <li>Sammanfattning</li>
  </ul>
  
  <p>Bok_Forfattare (eng. Book_Author)</p>
  
  <ul>
  <li>Bok_ForfattareID</li>
  <li>BokID</li>
  <li>ForfattareID</li>
  </ul>
  
  <p>Forfattare (eng. Author)</p>
  
  <ul>
  <li>ForfattareID</li>
  <li>Fornamn </li>
  <li>Efternamn</li>
  </ul>
  
  <blockquote>
  <pre><code>&lt;%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master"
  
      Inherits="System.Web.Mvc.ViewPage&lt;BokButik1.ViewModels.SokningPerformSearchViewModel&gt;"
  </code></pre>
    
    <p>%></p>
  
  <pre><code>&lt;asp:Content ID="Content1" ContentPlaceHolderID="TitleContent"
  </code></pre>
    
    <p>runat="server">
          PerformSearch
        </p>
    
    <p></p>
  
  <pre><code>&lt;h2&gt;Sökresultat&lt;/h2&gt;
  
  
  &lt;table&gt;
  &lt;% foreach (var bok in Model.Boks) { %&gt; 
  
  
  &lt;tr&gt;
      &lt;td&gt;&lt;%: bok.Titel %&gt; av &lt;%: bok.Bok_Forfattare %&gt;&lt;/td&gt;
      &lt;td rowspan="2"&gt;&lt;%: bok.Kategori.KategoriNamn %&gt;&lt;/td&gt;
      &lt;td rowspan="2"&gt;&lt;div id="Div1"&gt;&lt;input type="submit"
  </code></pre>
    
    <p>value="+ Add to cart" />
        
        
            &lt;%: bok.Sammanfattning %>
        
            
            .. 
        </p>
  
  <pre><code>&lt;% } %&gt; 
  &lt;/table&gt;
  </code></pre>
    
    <p></p>
  </blockquote>
  
  <hr>
  
  <pre><code>[AcceptVerbs(HttpVerbs.Post)]
  public ActionResult PerformSearch(string txtSearch, Kategori kategoriNummer)
  {
  
      Search test = new Search(txtSearch, kategoriNummer);
  
      var asdf = test.HamtaBokListaFranSokFunktion();
  
      var results = new SokningPerformSearchViewModel
      {
          Boks = asdf,
          Bok_Forfattares = myIBok_ForfattareRepository.HamtaAllaBok_ForfattareNummer()
      };
  
  
      return View(results);   
  }
  </code></pre>
  
  <hr>
  
  <pre><code>namespace BokButik1.ViewModels
  {
      public class SokningPerformSearchViewModel
      {
          public List&lt;Bok&gt; Boks { get; set; }
  
          public List&lt;Bok_Forfattare&gt; Bok_Forfattares { get; set; } 
      }
  }
  </code></pre>