I get the above issue when trying to implement a Dropdown list having Sessions from session activities table. Method in Controller
private void getSessions()
{
try
{
ViewData["Sessions"] = new SelectList(_dbContext.Set<SessionActivity>().Select((x) => new { x.Name, x.SessionDatum.Id }).ToList(), "Id", "Name");
}
catch (Exception ex)
{
_logger.Error(ex.Message, ex);
}
}
Coding's used in View
@{
var sessionSelect = (IEnumerable<SelectListItem>)ViewData["Sessions"];
}
@Html.DropDownList("SessionSelect",sessionSelect, "Please select..", new { @class = "form-control", @id = "SessionSelect" })
try to use SelectListItem