我得到这个错误“CS1928:DropDownListFor ASP MVC4
'System.Web.Mvc.HtmlHelper' 并不 不包含 'DropDownListFor' 和最佳推广 方法重载 “系统的定义。 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时遇到同样的错误。
它工作。谢谢。我不知道与SelectList和List的那部分。你帮了我很多。 – user2718165