我正在使用ASP.NET Core RC2 MVC與實體框架並試圖保存一輛新車。問題是,在汽車控制器的創建方法中,屬性顏色是null當操作回發時。所有其他屬性/字段均已設置。但是指代CarColors模型的顏色爲空。ASP.NET核心MVC模型屬性綁定爲空
的CarColor模型
public class CarColor
{
[Key]
public int CarColorId { get; set; }
[MinLength(3)]
public string Name { get; set; }
[Required]
public string ColorCode { get; set; }
}
主要模型車
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; }
}
的汽車控制器
[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);
}
請求數據:
的
調試截圖ü可以給我伸出援助之手,財產如何能夠被「綁定」等等ModelState.IsValid ==真?
莫非英語新我們如何請求? –
儘管ASP.NET 5,這可能有助於https://lbadri.wordpress.com/2014/11/23/web-api-model-binding-in-asp-net-mvc-6-asp-net-5/ – Set
添加了發佈請求數據的屏幕截圖。 –