title: ASP.NET MVC 2 Create Model using POST
body: <p>I have the following model:</p>
  
  <pre><code>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; }
  }
  </code></pre>
  
  <p>I have an action in my controller which is used to create a new product. My question is how to limit the properties of my model which can be bound from the POST data? Because I want only the Name and CategoryId to be bound by the user POST data. Or is it better to create a separate viewmodel which has only these properties that can be bound?</p>
  
  <pre><code>public ActionResult Create(Product p)
  </code></pre>
  
  <p>or</p>
  
  <pre><code>public ActionResult Create(CreateProductViewModel model)
  </code></pre>
  
  <p>where</p>
  
  <pre><code>public class CreateProductViewModel {
   public string Name {get; set;}
   public int CategoryId {get;set;}
  }
  </code></pre>