Gcobani Mkontwana

Gcobani Mkontwana

  • 546
  • 1.9k
  • 410k

System.InvalidOperationException: 'There is no ViewData item of type '

Sep 7 2020 6:33 AM
Hi Team
 
I am trying to fix this errror and was not successfull, can anyone mate help me on this error.
  1. public ActionResult CourseList()   
  2.       {  
  3.           var list = new List<string>() { "Private(Copyrighted)""Public Domain""Creative Commons Licences""CC Attribution""CC Attribution Share ALike""CC Attribution Non-Commercial",  
  4.           "CC Attribution Non-Commercial Share Alike""CC Attribution Non Directive""CC Attribution Non-Commercial No Directives" };  
  5.   
  6.           List<SelectListItem> select_list = new List<SelectListItem>();  
  7.   
  8.           var query = from li in list  
  9.                       select new SelectListItem()  
  10.                       {  
  11.                           Value = li.ToString(),  
  12.                           Text = li.ToString(),  
  13.                       };  
  14.           select_list = query.ToList();  
  15.           ViewBag.list = select_list;  
  16.   
  17.           return View();  
  18.       }  
  19.                      @using (Html.BeginForm("CourseList""Home", FormMethod.Post))  
  20.                                       {  
  21.                                       <div class="form-group row">  
  22.                                           <label for="Content-Licence" class="col-sm-3 col-form-label">Content Licence</label>  
  23.                                           <div class="col-sm-5">  
  24.                                               @Html.DropDownListFor(m => Model.Dashboard.CourseLicence, ViewBag.list as List<SelectListItem>)   // This throws an error here: no ViewData item of type.
  25.                                           </div>  
  26.                                           </div>  
  27.                                         
  28.                                       }  
  29. public class RegCoursesViewModel  
  30.   {  
  31.       public eNtsaCourses Courses { getset; }  
  32.       public eNtsaDashboardViewModel Dashboard { getset; }  
  33.       public List<eNtsaDashboardViewModel> lsteNtsaDashboard { getset; }  
  34.       public RegCoursesViewModel MainModel { getset; }  
  35.   
  36.   }  
 

Answers (2)