我有一个带有静态selectList的DropDownListFor
代码:
@Html.DropDownListFor(model => model.FinancialInfo.FinancialExpiryMonth,
new SelectList(Enumerable.Range(1, 12)),
(Model.FinancialInfo == null
|| Model.FinancialInfo.ExpiryDate == null)
? String.Empty
: null,
new { @class = "description-text" })
我需要第一项是单词Month
我怎么能用这个静态DropDownListFor
做到这一点?
答案 0 :(得分:0)
我不确定你在DropDownListFor
检查了什么,但我建议你这样做:
@Html.DropDownListFor(model => model.FinancialInfo.FinancialExpiryMonth,
//Genaration of month names
Enumerable.Range(1, 12).Select(x=> new SelectListItem
{
Value = x.ToString(),
Text = System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(x)
}),
"Month", //First Value if nothing selected
new { @class = "description-text" })
答案 1 :(得分:-1)
最后解决了当项目等于Model Value
@Html.DropDownListFor(model => model.FinancialInfo.FinancialExpiryMonth, Enumerable.Range(1, 12).Select(x => new SelectListItem
{
Value = x.ToString(),
Text = System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(x),
}), "Month", new { @class = "description-text" })