我想建立一個簡單的下拉列表爲我的MVC應用程序。我有一個方法,讓我一個列表,它具有帳戶名稱,編號,刪除等等屬性,並擁有不同的銀行賬戶。然而建設DropDownList和Asp.Net MVC
public ActionResult AccountTransaction(AccountTransactionView model)
{
List<AccountDto> accounts = Services.AccountServices.GetAccounts(false);
AccountTransactionView v = new AccountTransactionView();
v.Accounts = (from a in accounts
select new SelectListItem
{
Text = a.Description,
Value = a.AccountId.ToString(),
Selected = false
});
return View();
}
,它的失敗,說我不能IEnumerable的SelectListItem轉換爲:
在我的控制,我打電話這一點,那麼使用LINQ,試圖建立一個SelectItemList ......像這樣的SelectList。
我AccountTransactionView的定義是這樣的:
public class AccountTransactionView
{
public SelectList Accounts { get; set; }
public int SelectedAccountId { get; set; }
}
可能重複(HTTP:/ /stackoverflow.com/questions/4833652/asp-net-mvc-with-drop-down-list-and-selectlistitem-assistance) – 2011-01-29 08:28:13