Gcobani Mkontwana

Gcobani Mkontwana

  • 568
  • 1.9k
  • 406.5k

Save functionality does not work

Aug 19 2020 8:36 AM
Hi Team
 
I want to make my save functionality to work, but it does not keep any record to my table and need some help. In summary what i want here is when a user creates a course, the coursename must stored to the table as raw data, so can see it to the course dashboard. Mine does not keep any record, here my logic below;
  1.  [Route("Home/CoursesRegistration")]    
  2.       public ActionResult CoursesRegistration( eNtsaRegCourses collection)    
  3.         {    
  4.             if(ModelState.IsValid)    
  5.             {    
  6.                     
  7.                 cb.SaveChanges();    
  8.                 return RedirectToAction("Courses""Home");    
  9.             }    
  10.                 
  11.             return View(collection);    
  12.         }    
  13.  //GET://Courses/Courses-All.    
  14.         [Route("Home/Courses")]    
  15.       public ActionResult Courses(string g) // This method must keep those record, when user register the course-name.    
  16.         {    
  17.             return View(g);    
  18.         }    
  19.     
  20. // Model    
  21. using System;    
  22. using System.Collections.Generic;    
  23. using System.Linq;    
  24. using System.Web;    
  25. using System.Data.Entity;    
  26. using eNtsaRegistrationTraining.Models;    
  27.     
  28. namespace eNtsaRegistrationTraining.DAL    
  29. {    
  30.     public class eNtsaRegCourses:DbContext    
  31.     {    
  32.     
  33.         public eNtsaRegCourses(): base("eNtsaRegCourses")    
  34.         {    
  35.     
  36.         }    
  37.         public DbSet<eNtsaCourses> eNtsaCourse { getset; }    
  38.         protected override void OnModelCreating(DbModelBuilder modelBuilder)    
  39.         {    
  40.             Database.SetInitializer<eNtsaRegistration>(null);    
  41.             base.OnModelCreating(modelBuilder);    
  42.         }    
  43.     }    
  44. }    
  45.     
  46. // Model    
  47. // db-schema lists.    
  48. public class eNtsaCourses    
  49. {    
  50.     [Key]    
  51.     public Guid? Id { getset; }    
  52.     public string Course { getset; }    
  53.         public string Nickname { getset; }    
  54.         public string Term { getset; }    
  55.         public string EnrolledAs { getset; }    
  56.         public bool Published { getset; }    
  57. }  
  1. // View  
  2. <div class="modal-footer">  
  3. <button type="button" class="btn btn-secondary" data-dismiss="modal">Cancel</button>  
  4. <a class="btn btn-large btn-success" id="fire" href="@Url.Action("CoursesRegistration", "Home")">Create Courses</a>  
  5. <script type="text/javascript" src="~/Scripts/jquery-3.4.1.js"></script>  
  6. <script type="text/javascript">  
  7. $('#fire').on('click'function (e) {  
  8. var url = '@Url.Action("CoursesRegistration", "eNtsaCourses")';  
  9. $(jQuery.noConflict);  
  10. $('#ModalContent').load(url, function (html) {  
  11. var form = $("#Modal-eNtsaCourses form");  
  12. $.validator.unobtrusive.parse(form);  
  13. $("#Modal-eNtsaCourses").modal('show');  
  14. form.submit(function () {  
  15. $.ajax({  
  16. url: this.action,  
  17. type: this.method,  
  18. data: $(this).serialize(),  
  19. success: function (result) {  
  20. $('#Modal-eNtsaCourses').modal('hide');  
  21. var content = '@Url.Action("Courses", "eNtsaCourses")';  
  22. $('#ViewCourses').load(content);  
  23. }  
  24. });  
  25. return false;  
  26. });  
  27. });  
  28. });  
  29. </script>  
  30. </div>  

Answers (3)