Reputation: 99
ModelState Isvalid is returning false when Primary Key is 0 on Creation.
In model:
[Key]
public int CourseId { get; set; }
In database:
database data:
In View:
ModelState IsValid return false:
Any idea why is it invalid?
Upvotes: 0
Views: 751
Reputation: 39
Try this approach. Don't return a null value and instead return a new instance of Course
public ViewResult AddCourse(int id)
{
var course = yourservice.GetById(id);
if(customer == null)
{
course = new Course();
}
return View(course);
}
}
Upvotes: 1