如何从控制器的视图上的下拉列表中获取选定的值?
模型:
public class CustomerInformation
{
public Dictionary<int, string> State { get; set; }
public CustomerInformation()
{
State = new Dictionary<int, string>()
{
{ 0, "California"},
{ 1, "Nevada"}
};
}
}
控制器
public ActionResult Index()
{
var model = new CustomerInformation.Models.CustomerInformation();
return View(model);
}
public ActionResult ShowData(CustomerInformation.Models.CustomerInformation _customerInformation)
{
//..
}
看法
@using (Html.BeginForm("ShowData", "Home"))
{
@Html.Label("State:: ");
@Html.DropDownListFor(m => m.State, new SelectList(Model.State, "Key", "Value"))
<input type="submit" value="Submit" />
}