title: Add custom attributes to table rendered by WebGrid
body: <p>I am using an MVC3 WebGrid, and want to add custom attributes of the form "data-xxx" to the <code>&lt;table&gt;</code> element rendered by <code>WebGrid.GetHtml()</code>.</p>
  
  <p>I tried to do this as follows:</p>
  
  <pre><code>grid.GetHtml(...
      htmlAttributes: new { data_xxx = "value" }
  );
  </code></pre>
  
  <p>However this renders as:</p>
  
  <pre><code>&lt;table ... data_xxx="value"&gt;
  </code></pre>
  
  <p>instead of the expected:</p>
  
  <pre><code>&lt;table ... data-xxx="value"&gt;
  </code></pre>
  
  <p>I.e. unlike other MVC helpers, it doesn't replace the underscore in the property name with a hyphen.</p>
  
  <p>After a bit of spelunking with Reflector it seems that:</p>
  
  <ol>
  <li><p><code>WebGrid.GetHtml()</code> calls <code>System.Web.WebPages.Html.ObjectToDictionary</code> to convert the anonymous attributes object to a dictionary.  Unlike the method <code>System.Web.Mvc.HtmlHelper.AnonymousObjectToHtmlAttributes</code> used by other helpers, this doesn't replace "_" by "-".</p></li>
  <li><p>Unlike most other MVC helpers, <code>WebGrid.GetHtml()</code> does not have an overload that takes an <code>IDictionary&lt;string, object&gt;</code>, so I can't work around the bug by specifying the attributes in this way.</p></li>
  </ol>
  
  <p>This looks like a bug to me, and I've submitted it to Connect:</p>
  
  <p><a href="http://connect.microsoft.com/VisualStudio/feedback/details/767456/webgrid-gethtml-helper-does-not-allow-data-attributes-to-be-set" rel="nofollow">http://connect.microsoft.com/VisualStudio/feedback/details/767456/webgrid-gethtml-helper-does-not-allow-data-attributes-to-be-set</a></p>
  
  <p>Any suggestions for a workaround?  Or is it fixed in MVC4?</p>