title: Difficulty repopulating viewmodels on post
body: <p>I have various viewmodels that have properties that must be populated. For example, imagine a database table full of countries. I have a create user page, and one of the properties on the viewmodel is <code>List&lt;string&gt; Countries</code>.</p>
  
  <p>Originally I populated this in a parameterless constructor, ie.</p>
  
  <pre><code>public CreateUserViewModel()
  {
     this.Countries = new CountryManager().GetCountries();
  }
  </code></pre>
  
  <p>But I read this is a bad practice, and I should pass them in.</p>
  
  <pre><code>public CreateUserViewModel(IEnumerable&lt;string&gt; countries)
  {
     this.Countries = countries;
  }
  </code></pre>
  
  <p>But in my post, this data is lost, and if validation fails it redirects to the view, but then the countries property is null.</p>
  
  <p>I am wondering how I should be repopulating this value. Manually putting some code into the controller post method seems bad, eg.</p>
  
  <pre><code>[HttpPost]
  public ActionResult CreateUser(CreateUserViewModel vm)
  {
    if (Model.IsValid)
    {
        new UserManager().CreateUser(vm);
    }
    else
    {
       vm.Countries = new CountryManager().GetCountries();
       return View(vm);
    }
  }
  </code></pre>
  
  <p>I am struggling to google what is probably a very common question. Any ideas?</p>