我的应用程序是 asp.net MVC,试图将 Telerik MVC Combobox 绑定到模型。这是模型:
public class Person
{
public int Id { get; set; }
public string Name { get; set; }
public bool DisplayBold { get; set; }
public string Value
{
get
{
return string.Format("{0}|{1}", this.Id, this.DisplayBold.ToString());
}
}
}
在控制器中:
var people = new List<Person>();
people.Add(new Person { Id = 1, Name = "John Doe", DisplayBold = true });
people.Add(new Person { Id = 2, Name = "Jayne Doe", DisplayBold = false });
ViewData["people"] = people;
return View();
我确实得到了价值观。
在视图中:
<%= Html.Telerik().ComboBox()
.Name("ComboBox")
.BindTo((IEnumerable<SelectListItem>)ViewData["people"])
%>
我收到以下错误:
Unable to cast object of type 'System.Collections.Generic.List`1[caseprog.Models.Person]' to type 'System.Collections.Generic.IEnumerable`1[System.Web.Mvc.SelectListItem]'.
我会很感激你的建议。提前致谢。