Reputation: 5550
I set the the LOV of dropdownlist in Controller by putting them into a ViewData and displaying them at View using the following code:
@Html.DropDownList("dropDown_"+item.ConfigCode);
The dropdownlist does displayed as I wanted and I'm now stuck at changing the width of it. Based on what I've found on the net, the following code should be working, however, it is not showing any value for the drop down list. May I know what should I do with it?
@Html.DropDownList("dropDown_"+item.ConfigCode, Enumerable.Empty<SelectListItem>(),new { @style = "width: 50px;" })
Upvotes: 0
Views: 12784
Reputation: 78535
You don't need the @
before style and also you need to pass in the ViewData into the DropDownList source:
@Html.DropDownList("dropDown_"+item.ConfigCode, (IEnumerable<SelectListItem>)ViewData["dropDown_"+item.ConfigCode] ,new { style = "width: 50px;" })
You only need to escape keywords with the @
symbol if they are C# keywords, for example class
Upvotes: 10