我想在MVC中创建一个DropDownListFor,我有2个选项:“Active”,“non-Active”和2个值:“true”,“false”。如何将我的值放在选项中以及如何在我的控制器中获取这些值
查看:
@Html.DropDownListFor(p=>p.IsActivated, new SelectList(new[] { "Active", "non-Active" }), null, new { @class = "User-Input" })
型号:
public bool IsActivated { get; set; }
现在我找到了一条路。如果我们只需要2个选项并且请求是droplistdown,您可以使用此代码段:
@{
var list = new List<SelectListItem>(new[]
{
new SelectListItem
{
Text = "Active",
Value = "true"
}
new SelectListItem
{
Text = "non-Active",
Value = "false"
}
});
}
@Html.DropDownListFor(m => m.IsActivated, list, null, new { @class = "User-Input" })