产品型号:
public class Product
{
public int Id { get; set; }
public string Name { get; set; }
public int CategoryId { get; set; }
[ForeignKey("CategoryId")]
public Category Category { get; set; }
public string Description { get; set; }
public decimal Price { get; set; }
}
类别型号:
public class Category
{
public int Id { get; set; }
public string Name { get; set; }
public string Description { get; set; }
}
ProductController 与 ModelState.Isvalid = False
我尝试更改代码并尝试不同的外键方式。
我知道这是一个基本问题,但我无法得到结果。不将产品信息存储到数据库中。
错误纯粹是因为验证,在 Category 之前使用 [ValidateNever],这样属性永远不会被验证。