Hi Team
I am getting this exception when i try to access all list,
System.InvalidOperationException: 'There is no ViewData item of type 'IEnumerable<SelectListItem>' that has the key 'Dashboard.CourseLicence'.'
What I have tried:
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>
}
public class RegCoursesViewModel
{
public eNtsaCourses Courses { get; set; }
public eNtsaDashboardViewModel Dashboard { get; set; }
public List<eNtsaDashboardViewModel> lsteNtsaDashboard { get; set; }
public RegCoursesViewModel MainModel { get; set; }
}
public class eNtsaDashboardViewModel
{
public string CourseName { get; set; }
public string CourseLicence { get; set; }
}