这是我的代码:
@Html.DropDownListFor(m=> m.IsCurrentlySmoking, new{ onchange="RiskChange(this)", id="IsCurrentlySmokingLeftDrp", SelectList(new List<Object>{
new { value = 0, text = "Fortsatt rökning"},
new {value = 1, text = "Minskat rökning"},
new {value = 2, text = "Röker ej"},
}, "value", "text", 0)}
代码工作正常,直到我添加了id。现在我收到错误:CS0746:无效的匿名类型成员声明符。必须使用成员分配,简单名称或成员访问声明匿名类型成员。
代码有什么问题?我已经将id添加到其他mvc表单元素中,并且它工作得很好。
答案 0 :(得分:2)
您搞砸了SelectList
和htmlAttributes
订单。只需改变它,就可以了:
@Html.DropDownListFor(m => m.IsCurrentlySmoking, new SelectList(new List<Object>{
new { value = 0, text = "Fortsatt rökning"},
new {value = 1, text = "Minskat rökning"},
new {value = 2, text = "Röker ej"},
}, "value", "text", 0), new { onchange = "RiskChange(this)", id = "IsCurrentlySmokingLeftDrp" })