✅ ModelState Validation Error
Hello, i've been trying to fix this error for a while now and couldn't understand the situation. ModelState Validation says Category field is required(pic 1) even tho it's not null(pic 2).
My Model(Product)
Category
My Model(Product)
{
public class Product
{
public int Id { get; set; }
public int CategoryId { get; set; }
public string Name { get; set; } = null!;
public string? Description { get; set; }
public string? ImagePath { get; set; }
public bool IsDeleted { get; set; }
public int? CreateUserId { get; set; }
public DateTime? CreatedAt { get; set; }
public int? UpdateUserId { get; set; }
public DateTime? UpdatedAt { get; set; }
public Category Category { get; set; }
public AdminUser? CreatedBy { get; set; }
public AdminUser? UpdatedBy { get; set; }
public ICollection<ProductPrice> Prices { get; set; } = new List<ProductPrice>();
}
}{
public class Product
{
public int Id { get; set; }
public int CategoryId { get; set; }
public string Name { get; set; } = null!;
public string? Description { get; set; }
public string? ImagePath { get; set; }
public bool IsDeleted { get; set; }
public int? CreateUserId { get; set; }
public DateTime? CreatedAt { get; set; }
public int? UpdateUserId { get; set; }
public DateTime? UpdatedAt { get; set; }
public Category Category { get; set; }
public AdminUser? CreatedBy { get; set; }
public AdminUser? UpdatedBy { get; set; }
public ICollection<ProductPrice> Prices { get; set; } = new List<ProductPrice>();
}
}Category
public class Category
{
public int Id { get; set; }
public string Name { get; set; } = null!;
public string? Description { get; set; }
public int DisplayOrder { get; set; }
public bool IsDeleted { get; set; }
public int? CreateUserId { get; set; }
public DateTime? CreatedAt { get; set; }
public int? UpdateUserId { get; set; }
public DateTime? UpdatedAt { get; set; }
public AdminUser? CreatedBy { get; set; }
public AdminUser? UpdatedBy { get; set; }
public ICollection<Product> Products { get; set; } = new List<Product>();
}public class Category
{
public int Id { get; set; }
public string Name { get; set; } = null!;
public string? Description { get; set; }
public int DisplayOrder { get; set; }
public bool IsDeleted { get; set; }
public int? CreateUserId { get; set; }
public DateTime? CreatedAt { get; set; }
public int? UpdateUserId { get; set; }
public DateTime? UpdatedAt { get; set; }
public AdminUser? CreatedBy { get; set; }
public AdminUser? UpdatedBy { get; set; }
public ICollection<Product> Products { get; set; } = new List<Product>();
}
