title: asp.net mvc 3 webgrid bound to List<dynamic> is exceedingly slow
body: <p>I need to display a data table that can return a variable number of columns in a view, so I am binding an Mvc 3 WebGrid to a List&lt;dynamic&gt;, as described in the answer to this post:  <a href="https://stackoverflow.com/questions/6168548/populate-mvc-webgrid-from-datatable">Populate MVC Webgrid from DataTable</a></p>
  
  <p>It works fine, but is incredibly slow!  By "incredibly slow" I mean it takes 13 seconds to display a set of 15 records with 11 columns.  Is there any way to speed this up?  I've tried removing the Pager but that has no effect.</p>
  
  <p>The code that creates the List&lt;dynamic&gt; from an Ado.Net data table looks like this.  It runs very quickly, no problem here.  </p>
  
  <pre><code>var MyList = new List&lt;dynamic&gt;();
  foreach (DataRow row in MyTable.Rows)
  {
     var expando = (IDictionary&lt;string, object&gt;)new ExpandoObject();
     foreach (string column in columnNames)
     {
         expando.Add(column, row[column]);
     }
     MyList.Add(expando);
  }
  </code></pre>
  
  <p>The problem occurs in the view. The code below takes about 13 seconds to render a set of 15 records with 11 columns! The trip to the database and the conversion of the data table to a List&lt;dynamic&gt; takes less than a second.  The code below takes 13 seconds, just to render.  What am I doing wrong?  Or am I just barking up the wrong tree using a List&lt;dynamic&gt;?</p>
  
  <pre><code>var grid = new WebGrid(canPage: true, rowsPerPage: Model.PageSize, canSort: false);
   grid.Bind(Model.MyList, rowCount: (int)Model.RowCount, autoSortAndPage: false);
   grid.Pager(WebGridPagerModes.All);
                  @grid.GetHtml(tableStyle: "webgrid",
                      rowStyle: "webgrid-row",
                      alternatingRowStyle: "webgrid-alternating-row",
                           htmlAttributes: new { id = "tblSearchResults" },
                           firstText: "&lt;&lt;First",
                           lastText: "Last&gt;&gt;", mode: WebGridPagerModes.All
                  )
  </code></pre>