我试图填充一个DropDownList,当我提交表单,以获得所选择的值:
这里是我的模型:
public class Book
{
public Book()
{
this.Clients = new List<Client>();
}
public int Id { get; set; }
public string JId { get; set; }
public string Name { get; set; }
public string CompanyId { get; set; }
public virtual Company Company { get; set; }
public virtual ICollection<Client> Clients { get; set; }
}
我的控制器:
[Authorize]
public ActionResult Action()
{
var books = GetBooks();
ViewBag.Books = new SelectList(books);
return View();
}
[Authorize]
[HttpPost]
public ActionResult Action(Book book)
{
if (ValidateFields()
{
var data = GetDatasAboutBookSelected(book);
ViewBag.Data = data;
return View();
}
return View();
}
我的表格:
@using (Html.BeginForm("Journaux","Company"))
{
<table>
<tr>
<td>
@Html.DropDownList("book", (SelectList)ViewBag.Books)
</td>
</tr>
<tr>
<td>
<input type="submit" value="Search">
</td>
</tr>
</table>
}
当我点击,在操作参数“书”总是空。 我究竟做错了什么?