[英]CS1973 error when trying to implement a ListBoxFor
I'm trying to implement a very simple multiple select in .NET where the drop-down values are dynamically created. 我正在尝试在.NET中实现一个非常简单的多项选择,在其中动态创建下拉值。
The Code: 编码:
I created a View Model: 我创建了一个视图模型:
public class FiltersViewModel
{
public int[] SelectedNatures { get; set; }
public IEnumerable<SelectListItem> Natures { get; set; }
public void FillNatures()
{
var repository = new LeadRepository();
IEnumerable<string> natures = repository.GetNatures();
var items = new List<SelectListItem> {};
foreach (var nature in natures)
{
items.Add(new SelectListItem {Value = (string) nature, Text = (string) nature});
Natures = items.ToArray();
}
}
}
I created an instance of the model in the controller: 我在控制器中创建了模型的实例:
public ActionResult Map()
{
var model = new FiltersViewModel {SelectedNatures = new int[] {}};
model.FillNatures();
ViewData.Model = model;
return View();
}
Then I added in the View: 然后我在视图中添加:
<%: Html.ListBoxFor(x => x.SelectedValues, Model.Values) %>
Error: 错误:
Compiler Error Message: CS1973: 'System.Web.Mvc.HtmlHelper' has no applicable method named "ListBoxFor" 编译器错误消息:CS1973:'System.Web.Mvc.HtmlHelper'没有名为“ ListBoxFor”的适用方法
Question: 题:
It seems this question deals with the same error. 看来这个问题处理相同的错误。 I'll try to see if the answer works.
我将尝试看看答案是否有效。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.