asp.net mvc SelectList help

  • Thread starter Thread starter rodchar
  • Start date Start date
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
 
<%= Html.DropDownList("UserProfileSettings.GridPageSize",
Model.GridSizes)%>

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

Peace and Grace,

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

Twitter: @gbworld
Blog: http://gregorybeamer.spaces.live.com

*******************************************
| Think outside the box! |
*******************************************
 
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?
 
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,


--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

Twitter: @gbworld
Blog: http://gregorybeamer.spaces.live.com

*******************************************
| Think outside the box! |
*******************************************
 
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,


--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

Twitter: @gbworld
Blog: http://gregorybeamer.spaces.live.com

*******************************************
| Think outside the box! |
*******************************************
 
Back
Top