0
我试图在.NET中实现一个非常简单的多选,其中下拉值是动态创建的。尝试实现列表框时发生CS1973错误
验证码:
我创建一个视图模型:
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();
}
}
}
我在控制器中创建模型的实例:
public ActionResult Map()
{
var model = new FiltersViewModel {SelectedNatures = new int[] {}};
model.FillNatures();
ViewData.Model = model;
return View();
}
然后我在视图中添加:
<%: Html.ListBoxFor(x => x.SelectedValues, Model.Values) %>
错误:
编译器错误信息:CS1973: 'System.Web.Mvc.HtmlHelper' 评选 “ListBoxFor” 没有适用的方法
问:
- 有一个更简单的方法来实现多选? (我只想 创建它,然后我用阿贾克斯接受输入)
- 我现在的代码有什么问题?
- 如何为我的选择选择课程和ID?
您使用的是什么版本的.NET? – Romoku
也许是一个愚蠢的问题,但我并不太熟悉使用Web窗体。 '<%:'语法做了什么?您是否尝试过使用'<%'或'<%='来代替? –
@Romoku 4.0和MVC2 –