How to create a single select list box that shows the selection using Razor

爱⌒轻易说出口 提交于 2019-12-05 21:19:15
Donuts

To create a single select list box you can use DropDownListFor but set a size attribute... so do this:

@Html.DropDownListFor(model => model.code,
         Model.codelist, 
         new Dictionary< string, object >() { { "size", "3"} })
MrJonez

User Html.DropDownList instead of Html.ListBox to create a single select box.

Well, I've sort of got an answer to question one - turns out it's the browser that changes the rendering from simple list to dropdown list if "multiple" is removed, so I'm going to have to be creative to solve that one.

Question Two remains - why doesn't Razor keep my selected value during rendering?

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!