在我看来我有一个枚举下拉列表 http://www.asp.net/mvc/overview/releases/mvc51-release-notes#Enum(Asp.Net MVC 5.1 中的新功能)。
@Html.EnumDropDownListFor(m => m.SelectedLicense,new { @class="form-control"})
如果我执行上面的代码,我会得到以下枚举的下拉列表。
public enum LicenseTypes
{
Trial = 0,
Paid = 1
}
但默认情况下我希望我的下拉列表有一个值(自定义文本)
这就是我尝试过的
@Html.EnumDropDownListFor(m => m.SelectedLicense,"Select a license" ,new { @class="form-control"})
but now the problem is when i run it, my dropdownlist looks like this
So, the default text I want to show doesn't appear by default.
If a user selects "select a license" and tries to submit the form, it does show an error saying "select a license" but it doesn't show as default text.
Something i need to change?
PS:图片为页面加载时的截图。默认情况下,它将显示“试用”作为选定选项。