c# - Html.BeginRouteForm 接受字符集属性

标签 c# asp.net-mvc-3 razor

我正在 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/

相关文章:

asp.net-mvc - 处理上传的文件而不保存它?

asp.net-mvc-3 - MVC3 Razor 循环中奇怪的隐藏字符

c# - c# if else 语句的时间复杂度

c# - 使用通用 JSON 对象的 .NET Core Web API 和 MongoDB 驱动程序

asp.net-mvc-3 - Azure AppFabric 缓存。错误代码<ERRCA0017> :SubStatus<ES0006>

asp.net-mvc-3 - 混合 Razor View 和 Web 表单母版页

asp.net-mvc - 如何在 nopCommerce v2.20 插件中创建 EditorTemplate

使用 MVC 捆绑时 CSHTML 文件中的 Javascript Intellisense

c# - 为了维护起见,是否应该避免某些编程构造(和其他)?

c# - 无法将 iOS Autolayout 乘数设置为零