我是ASP.NET MVC的新手,我很感謝任何關於我的問題的幫助。我已經在這個話題上做了大量的研究(顯然還不夠)。我需要將一個下拉列表綁定到表中的特定列,然後將其呈現在視圖中。我已經有查詢檢索控制器表:將視圖中的DropDownList綁定到使用ASP.NET MVC4的表中的列
public ActionResult SelectAccountEmail()
{
var queryAccountEmail = (from AccountEmail in db.UserBases select AccountEmail)
var selectItems = new SelectList(queryAccountEmail);
return View(selectItems);
}
的時候纔來查詢綁定到視圖中的下拉列表我迷路。
Server Error in '/' Application.
--------------------------------------------------------------------------------
The model item passed into the dictionary is of type 'System.Web.Mvc.SelectList', but this dictionary requires a model item of type 'RecordUploaderMVC4.Models.UserBase'.
任何幫助將不勝感激:
@model RecordUploaderMVC4.Models.UserBase
@{
ViewBag.Title = "SelectAccountEmail";
}
<h2>SelectAccountEmail</h2>
@Html.LabelFor(model => model.AccountEmail);
@Html.DropDownList(Model.AccountEmail);
@Html.ValidationMessageFor(model => model.AccountEmail);
<input /type="submit" value="Submit">
當我運行它,我得到這個錯誤。
在此先感謝。
視圖是期待RecordUplo aderMVC4.Models.UserBase作爲模型,並傳遞一個SelectList類型的對象。提供適當類型的模型對象。 – eka