Guest User

Guest User

  • Tech Writer
  • 2.1k
  • 480.8k

How to save List value to a database in ActionResult?

Sep 11 2020 6:17 AM
Hi Team
 
I am struggling to save List<SelectedIte> eNtsaDashboard = new List<SelectedItem>(); to db. Anyone can help me below logic?
  1.   public ActionResult SaveCourse(RegCoursesViewModel regCoursesView)  
  2.       {  
  3.           try  
  4.           {  
  5.               List<SelectListItem> eNtsaDashboard = new List<SelectListItem>();  
  6.               var courseName = regCoursesView.Dashboard.CourseName;  
  7.               var courseLicence = regCoursesView.eCourses.CourseLicence;  
  8.               cb.Courses.Add(regCoursesView.Courses);  
  9.               cb.SaveChanges();  
  10.           }  
  11.           catch (Exception ex)  
  12.           {  
  13.               var error = ex.Message.ToString();  
  14.           }  
  15.           return RedirectToAction("AllCourses");  
  16.       }  
  17. // eNtsaRegCourses.  
  18.   public class RegCoursesViewModel  
  19.   {  
  20.       public eNtsaCourses Courses { getset; }  
  21.       public eNtsaCourseList eCourses { getset; }  
  22.       public eNtsaDashboardViewModel Dashboard { getset; }  
  23.       public IEnumerable<SelectListItem> eNtsaDashboard { getset; }  
  24.       public RegCoursesViewModel MainModel { getset; }  
  25.   
  26.   }  
 

Answers (7)