I have a model. This model look like this:
public int Id { get; set; }
[Required]
public string Name { get; set; }
[Required]
public List<Category> Parent { get; set; }
In the add action I populate Parent:
public ViewResult Add()
{
var addCategoryModel = new CategoryEditModel
{
Parent = Mapper.Map<List<Category>>(_productRepository.Categories.ToList())
};
return View("add", addCategoryModel);
}
When I submit the form my model state always is invalid, because my selected value in DropDownList "..is invalid." I made something wrong. What is the correct way to do this?