title: MVC with Razor creating drop down list
body: <p>I have the follwing code, I m able to create a drop down list but when I submit, I get an Object reference not set to an instance of an object exception. <code>News</code> class has <code>Category</code> and Category class have Id, Name, Order.</p>
  
  <p>How can I fix this?  </p>
  
  <p>My view:</p>
  
  <pre><code>&lt;div class="editor-field"&gt;
    @Html.DropDownListFor(m =&gt; m.News.Category.Id, Model.Categories, "Select One")
    @Html.ValidationMessageFor(m =&gt; m.News.Category)
   &lt;/div&gt; 
  </code></pre>
  
  <p>The view model:</p>
  
  <pre><code>public class NewsViewModel
  {
      public string SelectedCategoryId { get; set; }
      public IEnumerable&lt;SelectListItem&gt; Categories { get; set; }
      public News News { set; get; }
  }
  </code></pre>
  
  <p>And the controller action:</p>
  
  <pre><code>[HttpPost]
  public ActionResult Create(NewsViewModel newsViewModel)
  {
      try
      {
          using (var session = NHibernateHelper.OpenSession())
          {
              using (var tx = session.BeginTransaction())
              {
  
                  session.Save(newsViewModel.News);
                  tx.Commit();
              }
          }
  
          return RedirectToAction("Index");
      }
      catch
      {
          return View();
      }
  }
  </code></pre>
  
  <p>I m getting the exception while saving the model <code>session.Save(newsViewModel.News);</code></p>