开发者

Defining a html5 data attribute in MVC

I'm trying to declare a Html.Radio button in 开发者_如何转开发my mvc app and want to output a data- attribute. Problem is c# does like "-"

<%= Html.RadioButton("defaultRadioButton", d.Link, d.IsDefault, new { data-link = d.Link })%>

Is there anyway to get round this other than outputting the html myself or creating a helper?

Thanks..


If this is ASP.NET MVC 3:

<%= Html.RadioButton(
    "defaultRadioButton", 
    d.Link, 
    d.IsDefault, 
    new { 
        data_link = d.Link 
    }
)%>

and the underscore will be automatically converted into a dash by the helper.

In previous versions of MVC an ugly hack could be appiled:

<%= Html.RadioButton(
    "defaultRadioButton", 
    d.Link, 
    d.IsDefault, 
    new Dictionary<string, object> { 
        { "data-link", d.Link } 
    }
) %>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜