我有一个带有下拉菜单的编辑器模板:
@Html.DropDownListFor(m => m.AdmissionState, new List<SelectListItem>()
{
new SelectListItem()
{
Text = "1",
Value = "1"
},
new SelectListItem()
{
Text = "2",
Value = "2"
},
new SelectListItem()
{
Text = "3",
Value = "3"
},
}, "- Select -")
我从视图中调用它:
@Html.EditorFor(m => m.Licenses)
在控制器中,我有以下代码:
profile.Licenses.Add(new AttorneyLicenseModel()
{
AdmissionDate = "06/14/2012",
AdmissionState = "2",
AdmissionNumber = "asd",
});
profile.Licenses.Add(new AttorneyLicenseModel()
{
AdmissionDate = "07/16/2012",
AdmissionState = "5",
AdmissionNumber = "qwe",
});
对于每个许可证,我都看到了从模型中填充数据的字段,但下拉列表中没有 - 选中了默认值。我究竟做错了什么?当然,带有值的代码非常简化