title: ASP.NET MVC 2 Using an interface to strongly type a partial
body: <p>I'm experimenting with ASP.NET MVC2, in particular viewmodels and partials. My question is: Is it ‘valid’ or ‘right’ to have your partials strongly typed against an interface and the have your viewmodels implement that interface if the view uses the partial?</p>
  
  <p>To illustrate, say I have a Product form partial (strongly typed against IProductFormViewModel) which is used in both the Edit and Create views. These views are strongly typed against ProductEditViewModel and ProductCreateViewModel which implement the IProductFormViewModel.</p>
  
  <p>The benefit being that the corresponding POST actions for Create and Edit take ProductCreateViewModel &amp; ProductEditViewModel objects respectively.</p>
  
  <hr>
  
  <p>Edit:
  If the partial has its own dedicated viewmodel (ProductFormViewModel) and each of the ProductEditViewModel &amp; ProductCreateViewModel expose a property of type ProductFormViewModel which is passed to the partial, then when the form is submitted the model binding of ProductEditViewModel &amp; ProductCreateViewModel doesn't work as the Edit and Create actions expect their respective object types...thats the reason for the approach.</p>