What HTML helper do I use to create a simple dropdownlist that doesn't take in any variables?

China☆狼群 提交于 2019-12-01 11:49:10

Use a select list with either a List of strings or a Dictionary of items (if you want different id's and values) inside your drop down list to define your values.

<%= Html.DropDownList("day", new SelectList(
    new Dictionary<int,string> { { 1, "Sunday" }, { 2, "Monday" } },
    "Key", "Value"))
%>

<%= Html.DropDownList("hour", new SelectList(
    new List<string>() { "1", "2", "3", "4" }))
%>

If they are static keep them as HTML. No sense complicating things.

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