title: MVC4: ViewModel is empty on [HttpPost]
body: <p>I'm trying to make a simple news system in MVC4. I'm very new at it, and I have a simple News base class that looks like this:</p>
  
  <p>NewsPost:</p>
  
  <pre><code>public class NewsPost
  {
      public virtual int Id { get; set; }
      public virtual string Subject { get; set; }
      public virtual string Content { get; set; }
  }
  </code></pre>
  
  <p>It's then attached to a category class like so:</p>
  
  <p><strong>NewsCategory</strong>:</p>
  
  <pre><code>public class NewsCategory
  {
      public virtual int Id { get; set; }
      public virtual string Name { get; set; }
      public virtual ICollection&lt;NewsPost&gt; NewsPosts { get; set; }
  }
  </code></pre>
  
  <p>I then have a controller for creating these NewsPosts:</p>
  
  <p><strong>NewsController</strong>:</p>
  
  <pre><code>private readonly INewMvcSiteDataSource _db;
  
  public NewsController(INewMvcSiteDataSource db)
  {
      _db = db;
  }
  
  [HttpGet]
  public ActionResult Create()
  {
      var model = new CreateNewsViewModel();
  
      model.Categories = new SelectList(_db.NewsCategories, "Id", "Name");
  
      return View(model);
  }
  
  [HttpPost]
  public ActionResult Create(CreateNewsViewModel newsModel)
  {
      if (ModelState.IsValid)
      {
          int id = int.Parse(newsModel.SelectedCategories.Single(f =&gt; f.Selected).Value);
      }
      return View(newsModel);
  }
  </code></pre>
  
  <p>And lastly, to facilitate with creating the NewsPost, I use a CreateNewsViewModel, like so:</p>
  
  <p><strong>CreateNewsViewModel</strong>:</p>
  
  <pre><code>public class CreateNewsViewModel
  {
      [Required]
      public string Subject { get; set; }
  
      [Required]
      public string Content { get; set; }
  
      public SelectList Categories { get; set; }
      public SelectList SelectedCategories { get; set; }
  }
  </code></pre>
  
  <p>My view looks like this:</p>
  
  <p><strong>Create.cshtml</strong>:</p>
  
  <pre><code>@model NewMvcSite.Models.CreateNewsViewModel
  
  @{
      ViewBag.Title = "Create";
  }
  
  &lt;h2&gt;Create&lt;/h2&gt;
  
  @using (Html.BeginForm()) {
      @Html.ValidationSummary(true)
  
      &lt;fieldset&gt;
          &lt;legend&gt;CreateNewsViewModel&lt;/legend&gt;
  
          &lt;div class="editor-label"&gt;
              @Html.LabelFor(model =&gt; model.Subject)
          &lt;/div&gt;
          &lt;div class="editor-field"&gt;
              @Html.EditorFor(model =&gt; model.Subject)
              @Html.ValidationMessageFor(model =&gt; model.Subject)
          &lt;/div&gt;
  
          &lt;div class="editor-label"&gt;
              @Html.LabelFor(model =&gt; model.Content)
          &lt;/div&gt;
          &lt;div class="editor-field"&gt;
              @Html.EditorFor(model =&gt; model.Content)
              @Html.ValidationMessageFor(model =&gt; model.Content)
          &lt;/div&gt;
          &lt;div class="editor-label"&gt;
              @Html.LabelFor(model =&gt; model.Categories)
          &lt;/div&gt;
          &lt;div class="editor-field"&gt;
              @Html.DropDownListFor(model =&gt; model.Categories, Model.SelectedCategories)
          &lt;/div&gt;
          &lt;p&gt;
              &lt;input type="submit" value="Create" /&gt;
          &lt;/p&gt;
      &lt;/fieldset&gt;
  }
  
  @section Scripts {
      @Scripts.Render("~/bundles/jqueryval")
  }
  </code></pre>
  
  <p>For some reason, my viewmodel isn't returned when I click the submit button to create the newspost, and since there is no parameterless constructor for [HttpPost] Create action, it fails with <em>"No parameterless constructor defined for this object."</em></p>
  
  <p>I've been trying going through other posts here stating the same problem, but I fail to see the connection between what they are doing and what I am doing. I hope there is someone out there who can help me.</p>
  
  <p>Thank you.</p>