Gcobani Mkontwana

Gcobani Mkontwana

  • 1.1k
  • 952
  • 50.9k

mvc bootstrap modal save not working

Aug 19 2020 12:01 PM
Hi Team
 
I have problem, my modal to create is not saving to my database table. Here is my logic;
  1. [Route("Home/CoursesRegistration")]  
  2. public ActionResult CoursesRegistration(eNtsaRegCourses model) {  
  3.   if (ModelState.IsValid) {  
  4.     ViewBag.Message = "Course created";  
  5.     ModelState.Clear();  
  6.     cb.SaveChanges();  
  7.     return PartialView("CoursesRegistration""Home");  
  8.   }  
  9.   
  10.   return View("eNtsaCourses", model);  
  11. }  
  12.   
  13. //GET://Courses/Courses-All.    
  14. [Route("Home/Courses")]  
  15. public ActionResult Courses(eNtsaCourses courses) {  
  16.   if (ModelState.IsValid) {  
  17.     var data = cb.eNtsaCourse.Add(courses);  
  18.   }  
  19.   return View(courses);  
  20. }  
  21. // db-schema lists.    
  22. public class eNtsaCourses    
  23. {    
  24.     [Key]    
  25.     public Guid? Id { getset; }    
  26.     public string Course { getset; }    
  27.     public string Nickname { getset; }    
  28.     public string Term { getset; }    
  29.     public string EnrolledAs { getset; }    
  30.     public bool Published { getset; }   
  31. }   
  1. <div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">  
  2. <div class="modal-dialog" role="document">  
  3. <div class="modal-content">  
  4. <div class="modal-header">  
  5. <h5 class="modal-title" id="exampleModalLabel">Start New Course</h5>  
  6. <button type="button" class="close" data-dismiss="modal" aria-label="Close">  
  7. <span aria-hidden="true">×</span>  
  8. </button>  
  9. </div>  
  10. <div class="form-group row">  
  11. <label for="CourseName" class="col-sm-3 col-form-label">CourseName</label>  
  12. <div class="col-sm-5">  
  13. @Html.EditorFor(model => model.CourseName, new { htmlAttributes = new { @class = "form-control", autofocus = "autofocus", placeholder = "CourseName" } })  
  14. </div>  
  15. </div>  
  16. <div class="form-group row">  
  17. <label for="Content-Licence" class="col-sm-3 col-form-label">Content Licence</label>  
  18. <div class="col-sm-5">  
  19. </div>  
  20. </div>  
  21. <div class="modal-footer">  
  22. <button type="button" class="btn btn-secondary" data-dismiss="modal">Cancel</button>  
  23. <a class='modal-link btn-xs btn-success' href="@Url.Action("CoursesRegistration", "Home")">Create Course</a>    
  24. <script type="text/javascript">  
  25. $(".modal-link").click(function() {  
  26. $('#exampleModal').modal('show');  
  27. });  
  28. </script>  
  29. </div>  

Brought to you by:

Answers (9)