2012-03-01 45 views
0

我在我的ascx页面中收到BC30203错误。MVC中的ascx页面中的标识符预期错误

BC30203:预期标识符。 (4号线 - 新[])

代码:

<%= Html.DropDownList(
"", 
new SelectList(
    new[] 
    { 
     new { Value = "true", Text = "Yes" }, 
     new { Value = "false", Text = "No" }, 
    }, 
    "Value", 
    "Text", 
    Model 
) 
) %> 

缺少什么?

+0

解决方案.. http://stackoverflow.com/questions/9568111/problems-converting-editorfor-to-dropdownlist – ZVenue 2012-03-05 16:51:01

回答

0

你缺少创造什么样的:

new SelectList(
new ListItem[] 
{ 
    new ListItem { Value = "true", Text = "Yes" }, 
    new ListItem { Value = "false", Text = "No" }, 
} 

当使用关键字new,你必须告诉你要创建它不会采取一种猜测什么编译器。

+0

我仍然得到同样的错误..请参阅这篇文章,看看我来自哪里... http://stackoverflow.com/questions/9517627/converting-html-editorfor-into-a-drop-down-html-dropdownfor – ZVenue 2012-03-01 20:22:22

+0

什么是'模型'在你的代码?它从何而来? – 2012-03-01 22:18:16

0

我看到的红旗是你没有给你的SelectList一个名字。

<%= Html.DropDownList("MySelect", 
new SelectList(
new[] 
{ 
new SelectListItem() { Value = "true", Text = "Yes" }, 
new SelectListItem() { Value = "false", Text = "No" }, 
}, 
"Value", 
"Text", 
Model 
) 
) %> 
+0

它仍然不喜欢它..我得到同样的错误与您的代码 – ZVenue 2012-03-01 20:32:37

+1

你知道你为什么在** selectedValue **参数中指定“模型”?我不确定那是否会导致你的错误,但我的直觉说你没有正确使用这个参数。在故障排除的精神,删除最后三个参数**“价值”,“文本”,模型** - 错误是否持续? – Jed 2012-03-01 20:42:04

0

DropDownList方法需要IEnumerable<SelectListItem>作为第二个参数。

尝试像这样在这里

<%= Html.DropDownList(
    "Name", 
    new List<SelectListItem>()  
    { 
     new SelectListItem() { Value = "true", Text = "Yes" }, 
     new SelectListItem() { Value = "false", Text = "No" }, 
    }, 
    "Value", 
    Model 
) 
) %> 
+0

SelectList继承IEnumerable 2012-03-02 08:27:01