I have the following model:
public class Product {
public int Id { get; set; }
public string Name { get; set; }
private int CategoryId { get; set; }
public Category Category { get; set; }
public string InventoryDetails { get; set; }
}
I have an action in my controller that is used to create a new product. My question is how to limit the properties of my model that may be associated with POST data? Because I want only the name and CategoryId to be connected by POST user data. Or is it better to create a separate view model that can only link these properties?
public ActionResult Create(Product p)
or
public ActionResult Create(CreateProductViewModel model)
Where
public class CreateProductViewModel {
public string Name {get; set;}
public int CategoryId {get;set;}
}
source
share