控制器:
public ActionResult Filter() { ViewBag.Accounts = BusinessLayer.AccountManager.Instance.getUserAccounts(HttpContext.User.Identity.Name); return View(); }
视图:
<td>Account: </td> <td>@Html.DropDownListFor("accountid",new SelectList(ViewBag.Accounts,"AccountID","AccountName"))</td>
ViewBag.Accounts包含具有AccountID,AccountName和其他属性的Account对象.
我想要一个名为accountid的DropDownList(以便在Form Post上可以传递所选的AccountID)和DropDownList以显示AccountName,同时使AccountID为值.
在代码中我做错了什么?