Model-View-Controller – MVC2 ViewData issue

I am trying to pass some list of items to the view via ViewData to create a drop-down list. This shouldn’t be too difficult, but I’m new to MVC, so I might be missing some obvious Stuff.

The controller assigns the list to ViewData:

ViewData["ImageLocatons"] = new SelectList(gvr.ImageLocations);< /pre> 

And the view tries to present it in the drop-down list:

<%= Html.DropDownList("Location", ViewData["ImageLocations"] as SelectList ) %>

But when I run it, I get this error:
No ViewData item of type "IEnumerable" has a "location" key.

Any Thoughts why this doesn't work? Also, shouldn't it look for the key "ImageLocations" instead of locations?

If you use:

ViewData["Location"] = new SelectList(gvr.ImageLocations);

and

<%= Html.DropDownList("Location")% >

Your life will be much easier.

When setting the ViewData in the example, also check for spelling errors (missing i) (ImageLocatons => ImageLocations). This will cause the pass The second parameter given to DropDownList is null. This will cause the MVC engine to search for Location.

I am trying to pass some list of items to the view via ViewData to create a drop-down list. It shouldn’t be too difficult, but I’m new to MVC, so I might be missing something obvious.

The controller assigns the list to ViewData:

< /p>

ViewData["ImageLocatons"] = new SelectList(gvr.ImageLocations);

And the view tries to present it in the drop-down list:

<%= Html.DropDownList("Location", ViewData["ImageLocations"] as SelectList) %>

But when I run it, I get this error:
No The ViewData item of type "IEnumerable" has a "location" key.

Any ideas why this doesn't work? Also, shouldn't it look for the key "ImageLocations" instead of locations?

If you use:

ViewData["Location"] = new SelectList(gvr .ImageLocations);

and

<%= Html.DropDownList("Location") %>

Your life will It’s a lot easier.

When setting the ViewData in the example, also check for spelling errors (missing i) (ImageLocatons => ImageLocations). This will cause the second parameter passed to the DropDownList to be null. This will Cause the MVC engine to search for Location.

WordPress database error: [Table 'yf99682.wp_s6mz6tyggq_comments' doesn't exist]
SELECT SQL_CALC_FOUND_ROWS wp_s6mz6tyggq_comments.comment_ID FROM wp_s6mz6tyggq_comments WHERE ( comment_approved = '1' ) AND comment_post_ID = 2131 ORDER BY wp_s6mz6tyggq_comments.comment_date_gmt ASC, wp_s6mz6tyggq_comments.comment_ID ASC

Leave a Comment

Your email address will not be published.