Witam,
mam problem z listboxem. Otóż chcę na listboxie wyświetlić dane z bazy danych. Wyświetlają się bez problemu, ale podczas przesyłania postem danych ModelState.IsValid ma wartość false, przez co nie mogę dalej przetworzyć formularza. Poniżej kod:
The parameter conversion from type 'System.String' to type 'System.Web.WebPages.Html.SelectListItem' failed because no type converter can convert between these types.
ApplicationDbContext db = new ApplicationDbContext();
var CurrentAcademicYearId = db.Settings.FirstOrDefault(a => a.Key.Equals(ApplicationConstants.SETTINGS_CURRENT_ACADEMIC_YEAR)).Value;
var groups = db.Groups.ToList().Where(a => a.AcademicYear.Id == CurrentAcademicYearId);
object[] items = new object[groups.Count()];
int index = 0;
foreach (Group group in groups)
{
items[index++] = new
{
Id = group.Id,
Name = group.Name
};
}
MultiSelectList groupsListItems = new MultiSelectList(items, "id", "name");
@Html.ListBoxFor(model => model.SelectedGroups, groupsListItems, htmlAttributes: new { @class = "form-control", size = "5" })
Co może być źle?