我正在尝试使用绑定枚举AgeRange
,Html.DropDownListFor
但无论我从“视图”页面中选择什么,Controller 都会获得值“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) };
}