我有一个文本框:
@Html.EditorFor(model => model.Type)Model.Type是一个字符串。对于这种类型,我想将其更改为DropDownList。我想要处理视图上的列表元素,我不想为此使用类。我失败的尝试是:
@Html.DropDownListFor(model=>model.Type,
new List<SelectListItem>
{
new SelectListItem {"Horror"},
new SelectListItem {"Fiction"},
new SelectListItem {"Romance"},
})在这种情况下,如何正确使用DropDownListFor?谢谢。
发布于 2015-01-27 14:02:40
就快到了。这
new SelectListItem {"Horror"}没有任何意义。
它应该是
new SelectListItem { Text = "Horror", Value = "Horror" }https://stackoverflow.com/questions/28172280
复制相似问题