c# - 如何将类添加到@Html.DropDownList?

标签 c# html css razor

最初,下拉值是从模型中加载的,现在需要加载“静态值”。所以我使用下面的类型为此加载下拉列表,我无法添加 CSS 类。需要建议

 @Html.DropDownList("RoundOffInterval", new List<SelectListItem>
 {
     new SelectListItem{ Text="Select Roundoff Interval",Value=""},
     new SelectListItem{ Text="5",Value = "5" },
     new SelectListItem{ Text="10", Value = "10" },
     new SelectListItem{ Text="15", Value = "15" },
     new SelectListItem{ Text="20", Value = "20" },
     new SelectListItem{ Text="30", Value = "30" }
})

在我使用以下类型之前:

@Html.DropDownListFor(m => m.RoundoffInterval, new SelectList(Model.RoundoffIntervalList, "Id", "Name"), "Select Roundoff Interval ", new { id = "RoundoffInterval", name = "RoundoffInterval", @class = "select2_demo_4 form-control" })

最佳答案

试试这个:

@Html.DropDownList(
"RoundOffInterval", 
 new List<SelectListItem>
        {
          new SelectListItem{ Text="Select Roundoff Interval",Value=""},
          new SelectListItem{ Text="5",Value = "5" },
          new SelectListItem{ Text="10", Value = "10" },
          new SelectListItem{ Text="15", Value = "15" },
          new SelectListItem{ Text="20", Value = "20" },
          new SelectListItem{ Text="30", Value = "30" },
       },
 new   {@class="select2_demo_4 form-control"})

关于c# - 如何将类添加到@Html.DropDownList?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34505726/

相关文章:

c# - 如何使用 BindingContext 将 Entry 绑定(bind)到 Xam.Plugins.Settings

c# - 使用 Tuple 的 TRest 组件

html - 我如何摆脱这个黑条?

javascript - 如何保持数据值(value)不变?

html - 光标在 IE10 中超出文本输入范围

css - 3 个固定列(页眉和页脚)使用 DIV,没有绝对 DIV,IE 友好,所有列均等拉伸(stretch)

c# - 如何返回视频(flv)路径以在flowplayer中显示?

c# - 从数据文件启动应用程序

javascript - 使用js将一个div的高度设置为与另一个div相同的高度

html - 如何在 CSS 中将标题垂直和水平居中?