asp.net-mvc Html.DropDownList 大小属性
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6635359/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Html.DropDownList size attribute
提问by Pete Davies
This is HTML
这是 HTML
<select size="25" style="width:100px" id="yearList"/>
This is Razor ( not sure if this is the correct term)
这是剃刀(不确定这是否正确)
@Html.DropDownList("yearList", null, new{style="width:100px;"})
Does anyone know how to give the Razor version a size attribute similar to the HTML version?
有谁知道如何给 Razor 版本一个类似于 HTML 版本的 size 属性?
Many thanks.
非常感谢。
回答by Darin Dimitrov
Like this:
像这样:
@Html.DropDownList(
"yearList",
Enumerable.Empty<SelectListItem>(), // <!-- TODO: bind with a real data
new {
size = "25",
style = "width: 60px"
}
)
回答by Serame Simon
open /Content/Site set the select class with the width, this will automatically be reflected on your page
打开 /Content/Site 用宽度设置选择类,这将自动反映在您的页面上
select
{
width:250px;
}

