剃刀中的选项选择对我不起作用

时间:2015-08-30 20:57:18

标签: c# asp.net-mvc

此代码对我不起作用:

<div class="col-md-4">
  @Html.DropDownListFor(m => m.etattik, 
    new SelectList(new List<Object>
    { 
      new { value = 0 , text="text1"  },
      new { value = 1 , text = "text2" },
      new { value = 2 , text = "text3"}
    })
  )
  @Html.ValidationMessageFor(m => m.etattik)
</div>

它显示了{ value = 0 , text=text1 }

2 个答案:

答案 0 :(得分:0)

您没有为dataValueField指定dataTextFieldSelectList

@Html.DropDownListFor(
                        m => m.etattik, 
                        new SelectList(
                                  new List<Object>{ 
                                   new { value = 0 , text="text1"  },
                                new { value = 1 , text = "text2" },
                                  new { value = 2 , text = "text3"}
                                }
                    , "value", "text")
                        )

答案 1 :(得分:0)

检查

C:\symbol\wntdll.pdb\69DDFBCBBC14421D8CB974F8EDC414102\wntdll.pdb