我收到此错误“CS1928:
'System.Web.Mvc.HtmlHelper' 不包含 'DropDownListFor' 的定义和最佳扩展方法重载 'System.Web.Mvc.Html.SelectExtensions.DropDownListFor(System.Web.Mvc.HtmlHelper, System.Linq.Expressions .Expression>, System.Collections.Generic.IEnumerable)' 有一些无效参数”
我的控制器看起来像这样
public class IndexController : Controller
{
public ActionResult Index()
{
EpfeSelectScreen model = new EpfeSelectScreen();
var b = (from a in dbEntitiesErste.CONFIG_APPLICATIONS
orderby a.APPLICATION_ID
select new EPFE.CustomDataObjects.CustomObjects
{
Text = a.APPLICATION_NAME,
Value = a.APPLICATION_ID
});
model.Application = b.OrderBy(x => x.Text).ToList();
return View(model);
}
}
我的模型是这个
public class EpfeSelectScreen
{
public string Search { get; set; }
public string selectedApplication { get; set; }
public List<SelectListItem> Country { get; set; }
public List<CustomObjects> Application { get; set; }
public List<SelectListItem> MetaData { get; set; }
public List<SelectListItem> References { get; set; }
public List<SelectListItem> ReferencedBy { get; set; }
public List<SelectListItem> TreeView { get; set; }
public EpfeSelectScreen()
{
Country = new List<SelectListItem>();
Application = new List<CustomObjects>();
References = new List<SelectListItem>();
ReferencedBy = new List<SelectListItem>();
TreeView = new List<SelectListItem>();
}
}
我的 CustomObjects 是这个
public class CustomObjects
{
public string Text { get; set; }
public short Value { get; set; }
}
我的 model.Application 中有一条记录,但是当该数据传递到我的视图时,我得到了那个错误。
我的视图看起来像这样
@model EPFE.Controllers.EpfeSelectScreen
@Html.DropDownListFor(m => m.selectedApplication, Model.Application)
如何解决这个问题呢?我究竟做错了什么?当我尝试使用 ListBoxFor 时,我得到了同样的错误。