title: Adding a hyphen to the html attribute name using MVC3 WebGrid helper
body: <p>I'm having a problem trying to add a custom HTML5 data attribute to the table that is rendered using the WebGrid helper.  I want the table tag look as follows:</p>
  
  <pre><code>&lt;table data-test="testdata"&gt;&lt;!-- Table Content --&gt;&lt;/table&gt;
  </code></pre>
  
  <p>Here is a sample view using the Razor view engine:</p>
  
  <pre><code>@{
      var myUser = new
      {
          Id = 1,
          Name = "Test User"
      };
  
      var users = new[] { myUser };
  
      var grid = new WebGrid(users);
  }
  @grid.GetHtml(htmlAttributes: new { data-test = "testdata"})
  </code></pre>
  
  <p>The last line will produce a "Invalid anonymous type member declarator." error, because of the hyphen in data-test.</p>
  
  <p>With some of the other input HtmlHelpers, you can use an underscore in place of the hyphen and it will be automatically changed to a hyphen when rendered.  This does not happen with the WebGrid.</p>
  
  <p>If I pass in a dictionary for htmlAttributes:</p>
  
  <pre><code>@grid.GetHtml(htmlAttributes: new Dictionary&lt;string, object&gt; {{ "data-test", "testdata"}})
  </code></pre>
  
  <p>the table gets rendered as such:</p>
  
  <pre><code>&lt;table Comparer="System.Collections.Generic.GenericEqualityComparer`1[System.String]" Count="1" Keys="System.Collections.Generic.Dictionary`2+KeyCollection[System.String,System.Object]" Values="System.Collections.Generic.Dictionary`2+ValueCollection[System.String,System.Object]"&gt;&lt;!-- Table Content --&gt;&lt;/table&gt;
  </code></pre>
  
  <p>What am I doing wrong and what should I do render the attribute as desired?</p>