asp.net mvc SelectList help

R

rodchar

Hi All,

I'm trying to bind a simple selectlist to my html.dropdownlist but not so
simple for me. I have this so far:

MODEL:
private void LoadDropDownLists(MorrisExpressContext
morrisExpressContext)
{
Dictionary<string, int> ddl = new Dictionary<string, int>();
ddl.Add("Select...", -1);
ddl.Add("15 Minutes", 15);
ddl.Add("30 Minutes", 30);
ddl.Add("60 Minutes", 60);
GridSizes = new SelectList(ddl);
}
VIEW:
<%= Html.DropDownList("UserProfileSettings.GridPageSize", Model.GridSizes)%>

RESULT:
[Select..., -1] is showing up in the dropdownlist (including the brackets)
instead of just showing the text part?

thanks,
rodchar
 
G

Gregory A. Beamer

<%= Html.DropDownList("UserProfileSettings.GridPageSize",
Model.GridSizes)%>

Have you ensured that you have bound GridSizes to the model?

Peace and Grace,
 
R

rodchar

found snippet that worked:

AppointmentDurations = new SelectList(
new[]
{
new { Value = 15, Name = "15 Minutes" },
new { Value = 30, Name = "30 Minutes" },
new { Value = 60, Name = "60 Minutes" }
}
, "Value", "Name");

btw, what does new[] mean?
 
G

Gregory A. Beamer

found snippet that worked:

AppointmentDurations = new SelectList(
new[]
{
new { Value = 15, Name = "15 Minutes" },
new { Value = 30, Name = "30 Minutes" },
new { Value = 60, Name = "60 Minutes" }
}
, "Value", "Name");

btw, what does new[] mean?.

Essentially, the code states:

Set up a new Select List and load it with a new array with 3 name value
pairs.

The new[] states that you are creating the class array.

peace and grace,
 
R

rodchar

Thanks for the help and insight.

Gregory A. Beamer said:
found snippet that worked:

AppointmentDurations = new SelectList(
new[]
{
new { Value = 15, Name = "15 Minutes" },
new { Value = 30, Name = "30 Minutes" },
new { Value = 60, Name = "60 Minutes" }
}
, "Value", "Name");

btw, what does new[] mean?.

Essentially, the code states:

Set up a new Select List and load it with a new array with 3 name value
pairs.

The new[] states that you are creating the class array.

peace and grace,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,276
Latest member
Sawatmakal

Latest Threads

Top