1
我試圖綁定枚舉AgeRange
使用Html.DropDownListFor
但無論我從視圖頁面中選擇的任何東西,控制器獲得值'0'。任何人都可以幫我解決這個問題嗎?Html.DropDownListFor總是返回值'0'無論選擇什麼
編輯:控制器代碼到位。
枚舉類:
public enum AgeRange
{
Unknown = -1,
[Description("< 3 days")]
AgeLessThan3Days = 1,
[Description("3-6 days")]
AgeBetween3And6 = 2,
[Description("6-9 days")]
AgeBetween6And9 = 3,
[Description("> 9 days")]
AgeGreaterThan9Days = 4
}
查看:
@Html.DropDownListFor(
model => model.Filter.AgeRangeId,
@Html.GetEnumDescriptions(typeof(AgeRange)),
new { @class = "search-dropdown", name = "ageRangeId" }
)
控制器:
public ActionResult Search(int? ageRangeId)
{
var filter = new CaseFilter { AgeRangeId = (AgeRange)(ageRangeId ?? 0) };
}
我建議你需要一個右括號所以我編輯 – 2012-04-24 07:09:50