我是 ASP.NET MVC 的新手,如果对我的问题有任何帮助,我将不胜感激。我已经对这个主题进行了大量研究(显然还不够)。我需要将下拉列表绑定到表中的特定列,然后在视图中呈现它。我已经有查询来检索控制器中的表:
public ActionResult SelectAccountEmail()
{
var queryAccountEmail = (from AccountEmail in db.UserBases select AccountEmail)
var selectItems = new SelectList(queryAccountEmail);
return View(selectItems);
}
在将查询绑定到视图中的下拉列表时,我迷失了方向。
@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">
运行时出现此错误:
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'.
任何帮助将不胜感激。
提前致谢。