私のアプリケーションは 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]'.
ご提案いただければ幸いです。前もって感謝します。