Get the selected drop down list value from a FormCollection in MVC
Posted
by James Santiago
on Stack Overflow
See other posts from Stack Overflow
or by James Santiago
Published on 2010-06-09T10:03:50Z
Indexed on
2010/06/13
8:02 UTC
Read the original article
Hit count: 556
I have a form posting to an action with MVC. I want to pull the selected drop down list item from the FormCollection in the action. How do I do it?
My Html form:
<% using (Html.BeginForm())
{%>
<select name="Content List">
<% foreach (String name in (ViewData["names"] as IQueryable<String>)) { %>
<option value="<%= name %>"><%= name%></option>
<% } %>
</select>
<p><input type="submit" value="Save" /></p>
<% } %>
My Action:
[HttpPost]
public ActionResult Index(FormCollection collection)
{
//how do I get the selected drop down list value?
String name = collection.AllKeys.Single();
return RedirectToAction("Details", name);
}
© Stack Overflow or respective owner