3

我正在 Razor 中构建一个表单,如下所示:

@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"/>
}

我需要在表单标签中获取一些属性。但是编译器不喜欢接受字符集中的破折号。我如何允许 C# 中的对象属性有破折号?

4

1 回答 1

4

在属性名称中使用下划线:accept_charset

MVC 自动将 html 属性属性中的下划线转换为破折号:

@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"/>
}

学分:如何在 ASP.NET MVC 的 HTML-5 data-* 属性中使用破折号

于 2013-07-17T16:05:40.597 回答