2013-07-17 112 views
3

我建立一个形式剃刀象下面这样:Html.BeginRouteForm接受-charset属性

@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#中的对象属性有一个破折号?

回答

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

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