【发布时间】:2013-01-31 14:23:45
【问题描述】:
我有一个响应提交按钮的表单。
我的菜单下拉列表如下:
@Html.DropDownList("State", new List<SelectListItem>
{
new SelectListItem { Text = "Please select" },
new SelectListItem { Value = "AL", Text="Alabama" }, ....
new SelectListItem { Value = "WY", Text="Wyoming" })
如何在我的模型中将选定的值作为 bool 或最好作为字符串 ..
我需要验证
[Required(ErrorMessage = "Please select a state.")]
public string/bool State { get; set; }
请帮忙。
谢谢
【问题讨论】:
-
这比它应该的要复杂。更好的是,您可以在 Action Partial 中创建它。这样您就可以在操作方法中创建选择列表
标签: asp.net asp.net-mvc asp.net-mvc-3 razor asp.net-mvc-4