1

I am getting BC30203 error in my ascx page.

BC30203: Identifier expected. (Line 4 - new[] )

Code:

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

What is missing ?

tereško
  • 58,060
  • 25
  • 98
  • 150
ZVenue
  • 4,967
  • 16
  • 61
  • 92
  • Solution here.. http://stackoverflow.com/questions/9568111/problems-converting-editorfor-to-dropdownlist – ZVenue Mar 05 '12 at 16:51

3 Answers3

0

You are missing what to create:

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

When using the new keyword, you must tell the compiler what you want to create it won't take a guess.

Shadow The GPT Wizard
  • 66,030
  • 26
  • 140
  • 208
  • I am still getting same error.. Please see this post to see where I am coming from... http://stackoverflow.com/questions/9517627/converting-html-editorfor-into-a-drop-down-html-dropdownfor – ZVenue Mar 01 '12 at 20:22
0

A red-flag that I see is that you are not giving a name to your SelectList.

<%= Html.DropDownList("MySelect", 
new SelectList(
new[] 
{ 
 new SelectListItem() { Value = "true", Text = "Yes" },
 new SelectListItem() { Value = "false", Text = "No" },
}, 
"Value", 
"Text",
Model
)
) %>
Jed
  • 10,649
  • 19
  • 81
  • 125
  • It still does not like it.. i am getting same error with your code – ZVenue Mar 01 '12 at 20:32
  • 1
    Do you know why you are specifying "Model" in the **selectedValue** parameter? I'm not sure whether or not that that is causing your error, but my gut says that you are not using that parameter correctly. In the troubleshooting spirit, remove the last three params **"Value","Text",Model** - Does the error persist? – Jed Mar 01 '12 at 20:42
0

The DropDownList method requires an IEnumerable<SelectListItem> as the 2nd parameter.

Try something like this

<%= Html.DropDownList(
   "Name",
   new List<SelectListItem>()    
   { 
       new SelectListItem() { Value = "true", Text = "Yes" },
       new SelectListItem() { Value = "false", Text = "No" },
   },
   "Value",
   Model
)
) %>
Patrick
  • 1,137
  • 1
  • 10
  • 23