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);
- }
Salman BegPosted Sep 1, 2020, 9:23 AM
Jaimin ShethiyaPosted Sep 1, 2020, 3:24 AM
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.
Rohit RaoPosted Aug 31, 2020, 6:10 AM