【发布时间】:2010-06-13 15:56:53
【问题描述】:
我有一个使用 MVC 发布到操作的表单。我想从操作中的 FormCollection 中拉出选定的下拉列表项。我该怎么做?
我的 HTML 表单:
<% 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>
<% } %>
我的行动:
[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);
}
【问题讨论】:
标签: c# html asp.net-mvc-2