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 ?

1

3 Answers 3

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.

Sign up to request clarification or add additional context in comments.

1 Comment

I am still getting same error.. Please see this post to see where I am coming from... stackoverflow.com/questions/9517627/…
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
)
) %>

2 Comments

It still does not like it.. i am getting same error with your code
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?
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
)
) %>

1 Comment

SelectList inherits IEnumerable<SelectListItem>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.