我正在 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"/>
}
我需要在表单标签中获取一些属性。但是编译器不喜欢 accept-charset 中的破折号。我如何允许 C# 中的对象属性有破折号?
最佳答案
在属性名中使用下划线: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"/>
}
来源:How to use dashes in HTML-5 data-* attributes in ASP.NET MVC
关于c# - Html.BeginRouteForm 接受字符集属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17704640/