2

Resolved

Custom attributes - underscores in name should be replaced

description

When passing custom attributes to helpers via anonymous object, the "_" should be replaced with "-" just like in MVC helpers

example:
    [Fact]
    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);
    }

comments

eilonlipton wrote Apr 15 at 11:20 PM

There's a common helper used in most of MVC and Web Pages that converts from a type to a dictionary and doing the underscore conversions. We probably need to change WebGrid from using RouteValueDictionary to use that helper.

kenegozi wrote Apr 16 at 10:13 PM

Happens across HtmlHelper in WebPages.
Work item title updated to reflect.
fix in code review