我有一个SelectList,它填充了数据库中的数据.数据来自a Dictionary<int, string>并填充SelectList,如下所示.
//...
Courses = new SelectList(GetCourses(),"Key","Value");
//...
Run Code Online (Sandbox Code Playgroud)
在视图上,它将数据库中的第一条记录显示为下拉列表中的默认选定值.我想清除此值并将下拉列表留空,以便用户可以手动选择一个值.如果可能的话,不使用javascript.
//I have this on the view
<%= Html.DropDownListFor(model => model.CourseID, Model.Courses) %>
Run Code Online (Sandbox Code Playgroud)
请帮忙!
<%= Html.DropDownListFor(model => model.CourseID, Model.Courses, string.Empty) %>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3308 次 |
| 最近记录: |