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;
- [Route("Home/CoursesRegistration")]
- public ActionResult CoursesRegistration( eNtsaRegCourses collection)
- {
- if(ModelState.IsValid)
- {
-
- cb.SaveChanges();
- return RedirectToAction("Courses", "Home");
- }
-
- return View(collection);
- }
-
- [Route("Home/Courses")]
- public ActionResult Courses(string g)
- {
- return View(g);
- }
-
-
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Web;
- using System.Data.Entity;
- using eNtsaRegistrationTraining.Models;
-
- namespace eNtsaRegistrationTraining.DAL
- {
- public class eNtsaRegCourses:DbContext
- {
-
- public eNtsaRegCourses(): base("eNtsaRegCourses")
- {
-
- }
- public DbSet<eNtsaCourses> eNtsaCourse { get; set; }
- protected override void OnModelCreating(DbModelBuilder modelBuilder)
- {
- Database.SetInitializer<eNtsaRegistration>(null);
- base.OnModelCreating(modelBuilder);
- }
- }
- }
-
-
-
- public class eNtsaCourses
- {
- [Key]
- public Guid? Id { get; set; }
- public string Course { get; set; }
- public string Nickname { get; set; }
- public string Term { get; set; }
- public string EnrolledAs { get; set; }
- public bool Published { get; set; }
- }
-
- <div class="modal-footer">
- <button type="button" class="btn btn-secondary" data-dismiss="modal">Cancel</button>
- <a class="btn btn-large btn-success" id="fire" href="@Url.Action("CoursesRegistration", "Home")">Create Courses</a>
- <script type="text/javascript" src="~/Scripts/jquery-3.4.1.js"></script>
- <script type="text/javascript">
- $('#fire').on('click', function (e) {
- var url = '@Url.Action("CoursesRegistration", "eNtsaCourses")';
- $(jQuery.noConflict);
- $('#ModalContent').load(url, function (html) {
- var form = $("#Modal-eNtsaCourses form");
- $.validator.unobtrusive.parse(form);
- $("#Modal-eNtsaCourses").modal('show');
- form.submit(function () {
- $.ajax({
- url: this.action,
- type: this.method,
- data: $(this).serialize(),
- success: function (result) {
- $('#Modal-eNtsaCourses').modal('hide');
- var content = '@Url.Action("Courses", "eNtsaCourses")';
- $('#ViewCourses').load(content);
- }
- });
- return false;
- });
- });
- });
- </script>
- </div>