Hi Team
I need some help with this exception, value cannot be empty. This is what i have on my application;
- // Model
- 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; }
- }
- // Controller
- //GET://Courses/Courses-All.
- [Route("Home/Courses")]
- public ActionResult Courses(RegCoursesViewModel eNtsaCourses)
- {
- if(ModelState.IsValid)
- {
- cb.eNtsaCourse.Add(eNtsaCourses.Courses);
- cb.SaveChanges(); // This throws an exception here
- }
- return View(eNtsaCourses);
- }
- [HttpPost]
- public JsonResult AddCoursesRegistration(string CourseName, string clientNo)
- {
- return Json(true, JsonRequestBehavior.AllowGet);
- }

Rohit RaoRank #2,002 · 726 reputationPosted Aug 31, 2020, 2:10 AM EDT
Jaimin ShethiyaRank #177 · 13.7K reputationPosted Aug 31, 2020, 11:24 PM EDT
1. can you please check the your context is null or not
2. In model you have define key attribute and that is nullable field, can you please remove the nullable that property.
3. can you also check the eNtsaCourse is null or not.
Thanks.
Salman BegRank #284 · 8.8K reputationPosted Sep 1, 2020, 5:23 AM EDT