U4-1891 - BeginUmbracoForm not converting html attributes with underscores to hyphen

Created by Eric Fredin 11 Mar 2013, 22:20:34 Updated by Sebastiaan Janssen 19 Dec 2013, 07:33:17

Html.BeingForm converts html attributes objects with underscores to hyphens to allow for attributes like "data-bind" to be defined. Html.BeginUmbracoForm is not translating these attributes.

Doesn't work: @using (Html.BeginUmbracoForm("Index", "MySurface" null, new { @data_bind = "myvalue" }))

Does work: @using (Html.BeginUmbracoForm("Index", "MySurface" null, new Dictionary<string, object>() { { "data-bind", "myvalue" } }))

Comments

Gary Hunt 21 Aug 2013, 21:21:44

Simple fix by using HtmlHelper.AnonymousObjectToHtmlAttributes which is what MVC uses internally to turn underscores into hyphens.

@@ -280,7 +280,7 @@ public static MvcForm BeginUmbracoForm(this HtmlHelper html, string action, stri object additionalRouteVals, object htmlAttributes) {

  •  return html.BeginUmbracoForm(action, controllerName, additionalRouteVals, htmlAttributes.ToDictionary<object>());
    
  •  return html.BeginUmbracoForm(action, controllerName, additionalRouteVals, HtmlHelper.AnonymousObjectToHtmlAttributes( htmlAttributes ));
    

    }

    ///

    @@ -596,4 +596,4 @@ public static HtmlTagWrapper Wrap(this HtmlHelper html, bool visible, string tag #endregion

    } -} +}


Sebastiaan Janssen 19 Dec 2013, 07:33:13

For reference, pull request: https://github.com/umbraco/Umbraco-CMS/pull/198


Priority: Normal

Type: Bug

State: Fixed

Assignee: Shannon Deminick

Difficulty: Very Easy

Category:

Backwards Compatible: True

Fix Submitted: Pull request, Inline code

Affected versions: 6.0.0, 6.1.0, 7.0.0, 6.0.1, 6.0.2, 6.0.3, 6.0.4, 6.1.1, 6.0.6, 6.0.5, 6.0.7, 6.1.2, 6.1.3, 6.1.4, 6.1.5, 6.1.6, 7.0.1

Due in version: 6.2.0, 7.0.2

Sprint:

Story Points:

Cycle: