简体   繁体   English

如何将新属性设置为@ Html.DropDownListFor

[英]How to set new attribute to a @Html.DropDownListFor

I'm trying to add an specific attribute (data-toggle="select") to my DropDownListFor. 我正在尝试将特定属性(data-toggle =“ select”)添加到我的DropDownListFor中。

When I use: 当我使用时:

@Html.DropDownListFor(model, myList, "Select..", new { @class = "form-control", @data-toggle="select" }). 

I get the error saying that "Cannot resolve symbol 'data'" and "Cannot resolve symbol 'toggle'" 我收到错误消息,提示“无法解析符号'数据'”和“无法解析符号'切换'”

What can I do so my DropDownListFor recognizes the attribute data-toggle? 我该怎么办,以使我的DropDownListFor识别属性data-toggle?

Ps: When I use 附:当我用

@Html.DropDownListFor(model, myList, "Select..", new { @class = "form-control"})

it works just fine 它很好用

答案实际上很简单,只需将您的-(破折号)替换为_(下划线),便会被设置。

@Html.DropDownListFor(model, myList, "Select..", new { @class = "form-control", @data_toggle="select" }).

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM