在MVC4中使用来自数据库的编辑值填充多个下拉列表

时间:2014-11-28 09:57:52

标签: asp.net-mvc asp.net-mvc-4

我正在使用数据库中的已编辑值生成多个下拉列表,下拉列表是 填充,但不包含已编辑的值。我正在根据List中的No of Element创建DropdownList。下面是代码示例------

@for (int a = 0; a < noofoption; a++)
  @Html.DropDownListFor(model => model.SameOptionList[a].qopanswer(IEnumerable<SelectListItem>)ViewBag.option, "--Select--")

SameOptionList是List Type属性。如果我没有使用List工作正常。

列表是填充但不是选定值。 Plz do Needful。

1 个答案:

答案 0 :(得分:1)

在集合中使用@Html.DropDownListFor时,您需要使用EditorTemplatethis answer

中给出了更详细的解释
相关问题