I am using ASP.NET Core RC2 MVC with Entity Framework and trying to save a new car. The problem is, that in the create method of the car controller the property Color is null when the action is posted back. All other properties/fields are set. But the Color which refers to the CarColors model is null.
The CarColor model
public class CarColor
{
[Key]
public int CarColorId { get; set; }
[MinLength(3)]
public string Name { get; set; }
[Required]
public string ColorCode { get; set; }
}
The main model Car
public class Car
{
[Key]
public int CarId { get; set; }
[MinLength(2)]
public string Name { get; set; }
[Required]
public DateTime YearOfConstruction { get; set; }
[Required]
public CarColor Color { get; set; }
}
The Cars controller
[HttpPost]
[ValidateAntiForgeryToken]
public async Task<IActionResult> Create([Bind("Color,Name,YearOfConstruction")] Car car)
{
if (ModelState.IsValid)
{
_context.Add(car);
await _context.SaveChangesAsync();
return RedirectToAction("Index");
}
return View(car);
}
The request data:
Debugging screenshot of the posted car
Can u give me a helping hand, how the property could be "bound" and so the ModelState.IsValid == true?

