Add custom attributes to table rendered by WebGrid
I am using an MVC3 WebGrid, and want to add custom attributes of the form "data-xxx" to the <table> element rendered by WebGrid.GetHtml() . I tried to do this as follows: grid.GetHtml(... htmlAttributes: new { data_xxx = "value" } ); However this renders as: <table ... data_xxx="value"> instead of the expected: <table ... data-xxx="value"> I.e. unlike other MVC helpers, it doesn't replace the underscore in the property name with a hyphen. After a bit of spelunking with Reflector it seems that: WebGrid.GetHtml() calls System.Web.WebPages.Html.ObjectToDictionary to convert the anonymous