MVC HTML.DropDownList设置宽度

Sui*_*eep 0 html asp.net-mvc razor

我通过将它们放入ViewData并使用以下代码在View中显示它们来设置Controller中的下拉列表的LOV:

@Html.DropDownList("dropDown_"+item.ConfigCode);
Run Code Online (Sandbox Code Playgroud)

下拉列表显示我想要的,我现在卡在改变它的宽度.根据我在网上找到的内容,以下代码应该正常工作,但是,它没有显示下拉列表的任何值.我可以知道我应该怎么做吗?

@Html.DropDownList("dropDown_"+item.ConfigCode, Enumerable.Empty<SelectListItem>(),new {      @style = "width: 50px;" }) 
Run Code Online (Sandbox Code Playgroud)

Cod*_*gue 10

您不需要@before样式,也需要将ViewData传递到DropDownList源:

@Html.DropDownList("dropDown_"+item.ConfigCode, (IEnumerable<SelectListItem>)ViewData["dropDown_"+item.ConfigCode] ,new { style = "width: 50px;" })
Run Code Online (Sandbox Code Playgroud)

@例如,如果符号是C#关键字,则只需要使用符号转义关键字class