Html.BeginRouteForm accept-charset attribute

asp.net-mvc-3, c#, razor

Solution

Use an underscore in the property name: accept_charset

MVC automatically convert underscores in html attribute properties to dashes:

@using (Html.BeginRouteForm("foo", new { controller = "foo", action = "bar" }, FormMethod.Post, new { id="foo", enctype="multipart/form-data", accept_charset="utf-8" }))
{       
    <label for="file">File</label>
    <input type="file" name="file" id="file" />
    <input type="submit" value="Send"/>
}

Credit: How to use dashes in HTML-5 data-* attributes in ASP.NET MVC

Problem

I'm building a form in Razor like below: ``` @using (Html.BeginRouteForm("foo", new { controller = "foo", action = "bar" }, FormMethod.Post, new { id="foo", enctype="multipart/form-data", accept-charset="utf-8" })) { <label for="file">File</label> <input type="file" name="file" id="file" /> <input type="submit" value="Send"/> } ``` I need to get some attributes in the form tag. But the compiler doesn't like the dash in accept-charset. How might I allow an object property in C# have a dash?

Original source

Related problems