title: ASP.NET MVC ViewModel Pattern
body: <p><strong>EDIT:</strong> I made something much better to <strong>fill and read data from a view using ViewModels</strong>, called it <strong>ValueInjecter</strong>. <a href="http://valueinjecter.codeplex.com/" rel="noreferrer">http://valueinjecter.codeplex.com/</a></p>
  
  <p>it is used by <a href="http://prodinner.codeplex.com" rel="noreferrer">http://prodinner.codeplex.com</a> - an ASP.net MVC sample application
   <p><strong>you can see the best way of using ViewModels in prodinner</strong></p></p>
  
  <p>using the ViewModel to store the mapping logic was not such a good idea because there was repetition and SRP violation, but now with the ValueInjecter I have clean ViewModels and dry mapping code <br/></p>
  
  <p><hr>
  <strong>That's the old stuff, don't use it:</strong><br/>
  <em>I made a ViewModel pattern for editing stuff in asp.net mvc
  this pattern is useful when you have to make a form for editing an entity and you have to put on the form some drop-downs for the user to choose some values</em></p>
  
  <pre><code>    public class OrganisationBadViewModel
      {
          //paramterless constructor required, cuz we are gonna get an OrganisationViewModel object from the form in the post save method
          public OrganisationViewModel() : this(new Organisation()) {}
          public OrganisationViewModel(Organisation o)
          {
              Organisation = o;
              Country = new SelectList(LookupFacade.Country.GetAll(), "ID", "Description", CountryKey);  
          }       
          //that's the Type for whom i create the viewmodel
          public Organisation Organisation { get; set; }
  ...     
  
      }
  </code></pre>