Нет элемента viewdata ошибки ienumerable<selectitem>?
Привет Команда
Я получаю это исключение, когда пытаюсь получить доступ ко всему списку,
System.InvalidOperationException: 'There is no ViewData item of type 'IEnumerable<SelectListItem>' that has the key 'Dashboard.CourseLicence'.'
Что я уже пробовал:
public ActionResult CourseList() { List<eNtsaDashboardViewModel> list = new List<eNtsaDashboardViewModel>() { new eNtsaDashboardViewModel { Text = "Private(Copyrighted)", Value = "1" }, new eNtsaDashboardViewModel { Text = "Public Domain", Value = "2" }, new eNtsaDashboardViewModel { Text = "CC Attribution Non Directive", Value = "3" }, new eNtsaDashboardViewModel { Text = "Creative Commons Licences", Value = "4" }, }; ViewBag.list = list; return View(); }
@using (Html.BeginForm("CourseList", "Home", FormMethod.Post)) { <div class="form-group row"> <label for="Content-Licence" class="col-sm-3 col-form-label">Content Licence</label> <div class="col-sm-5"> @Html.DropDownListFor(model => model.Dashboard.CourseLicence, ViewBag.list as List<SelectListItem>) </div> </div> }
// eNtsaRegCourses. public class RegCoursesViewModel { public eNtsaCourses Courses { get; set; } public eNtsaDashboardViewModel Dashboard { get; set; } public List<eNtsaDashboardViewModel> lsteNtsaDashboard { get; set; } public RegCoursesViewModel MainModel { get; set; } }
// This is for course-list. public class eNtsaDashboardViewModel { public string CourseName { get; set; } public string CourseLicence { get; set; } }