MVC - 清除SelectList的默认选择值

Nic*_*sao 4 c# asp.net-mvc

我有一个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)

请帮忙!

Cra*_*ntz 9

使用带有optionLabel的重载:

<%= Html.DropDownListFor(model => model.CourseID, Model.Courses, string.Empty) %>
Run Code Online (Sandbox Code Playgroud)