HtmlAttribute's using other controls automatically replace the "_" in the anonymous type to "-". The WebGrid doesn't and there is no direct access to the RouteValueDictionary on the renderer.
[Fact(DisplayName = "custom-test")]
public void WebGridCustomHtmlAttributeIsSpecified()
{
var grid = new WebGrid(GetContext(), ajaxUpdateContainerId: "grid")
.Bind(new[]
{
new { P1 = 1, P2 = '2', P3 = "3" },
new { P1 = 4, P2 = '5', P3 = "6" }
});
var html = grid.GetHtml(htmlAttributes: new {data_attribute = "value"});
string _html = html.ToHtmlString();
Assert.Contains("data-attribute", _html);
}
[Fact(DisplayName = "custom-test")]
public void WebGridCustomHtmlAttributeIsSpecified()
{
var grid = new WebGrid(GetContext(), ajaxUpdateContainerId: "grid")
.Bind(new[]
{
new { P1 = 1, P2 = '2', P3 = "3" },
new { P1 = 4, P2 = '5', P3 = "6" }
});
var html = grid.GetHtml(htmlAttributes: new {data_attribute = "value"});
string _html = html.ToHtmlString();
Assert.Contains("data-attribute", _html);
}