asp.net mvc中如何获取DropDownList控件选中的值
IQuery.aspx中,代码如下:
<p>
<label for="labname">按名字查找:</label>
<%=Html.DropDownList("DropDownListName")%>
<input type="submit" value="查询" />
</p>
<table>
<tr>
<th>
Name
</th>
<th>
Sex
</th>
<th>
BirthDate
</th>
<th>
MobilePhone
</th>
<th>
EMail
</th>
</tr>
<%foreach (var item in Model) { %>
<tr>
<td>
<%: item.Name %>
</td>
<td>
<%: item.Sex %>
</td>
<td>
<%: String.Format("{0:g}", item.BirthDate) %>
</td>
<td>
<%: item.MobilePhone %>
</td>
<td>
<%: item.EMail %>
</td>
</tr>
<% } %>
AddressBookRepository addressbookrepository = new AddressBookRepository();
public ActionResult IQuery(FormCollection formcollection)
{
ViewData["DropDownListName"] = new SelectList(db.tbAddressBooks, "Name", "Name");
string name = formcollection["DropDownListName"].ToString();
var addressbooks = addressbookrepository.GetAddressBookInName(name).ToList();
return View("IQuery", addressbooks);
}
断点调试时name的值为空,不知道什么原因,请大家帮帮忙,刚开始学,比较菜,说的详细点,感激不尽~~~
------解决方案--------------------
先通过Jquery获取值 并赋值到一个隐藏控件里
$("#DropDownList的ID").change(function(){
var selec = $(this).val();
// 将selec 赋值给隐藏控件
});
Action里面就直接获取隐藏控件ID的值 你试试