title: How to use a dynamic model to create a dynamic table
body: <p>I want to make one table, so I can load a class into it and the table will be automatically generated.</p>
  
  <p>This is what I am looking for, but I have no idea how I can realize this:</p>
  
  <pre><code>@model dynamic
  &lt;table&gt;
  &lt;thead&gt;
      &lt;tr&gt;
      @foreach(var record in model.results)
      {
          &lt;th&gt;@Html.labelfor(item.indexof(...))&lt;/th&gt;
      }
  
      &lt;/tr&gt;
  &lt;/thead&gt;
  @if (Model.Result.Count() &gt; 0)
  {
      &lt;tbody&gt;
          @for(int i = 0; i &lt; Model.Result.Count(); i++)
          {
              &lt;tr&gt;
                  @foreach (var item in Model.Result)
                  {  
                      &lt;td&gt;@item.indexOf(...)&lt;/td&gt;
                  }
              &lt;/tr&gt;
          }
      &lt;/tbody&gt;
  }
  else
  {
      &lt;p class="errordata"&gt;No data found...&lt;/p&gt;
  }
  </code></pre>
  
  <p></p>
  
  <p>This is my ViewModel:</p>
  
  <pre><code>public class issueModel
  {
      public int Id { get; set; }
      public string Name { get; set; }
      public string Color { get; set; }
      public string FontColor { get; set; }
      public int Count { get; set; }
      public string Description { get; set; }
      public string Abbreviation { get; set; }
      public string icon { get; set; }
      public List&lt;dynamic&gt; Result { get; set; }
  }
  </code></pre>
  
  <p>In the "List result" can be different, this is an example class that might be in the result:</p>
  
  <pre><code>public partial class someClass
  {
      [Display(Name = "PID_1")]
      public int? someProp_1{ get; set; }
  
      [Display(Name = "PID_2")]
      public int? someProp_2{ get; set; }
  
      [StringLength(255)]
      public string PermName1 { get; set; }
  
      [StringLength(255)]
      public string PermName2 { get; set; }
  
      public string description{ get; set; }
  
      public int? Prioriteit { get; set; }
  
      [StringLength(50)]
      public string Login { get; set; }
  
      public int id{ get; set; }
  }
  </code></pre>
  
  <p>I tried to use .indexOf on a dynamic item, but that doesn't work. Is the somehow a way to do this? Or do I have to make separate views with separate tables?</p>