title: comment db not getting updated in asp .net
body: <p>I am trying to create a simple blog application using asp.net. I am a novice and trying to teach myself c# and asp .net mvc.</p>
  
  <p>The problem that I am facing is that when I try to add a comment to a post then it doesn't work. I do get a comment attached to the post but it doesn't display anything. Also, when I check the database - it just contains Null fields except for the BlogID field. What am I doing wrong?</p>
  
  <p>My code is below:</p>
  
  <p>Blog - class</p>
  
  <pre><code>public class Blog
  {
      public int BlogID { get; set; }
      public string Title { get; set; }
      public string Writer { get; set; }
  
      [DataType(DataType.MultilineText)]
      public string Excerpt { get; set; }
  
      [DataType(DataType.MultilineText)]
      public string Content { get; set; }
  
      [DataType(DataType.Date)]
      public DateTime PublishDate { get; set; }
  
      public virtual ICollection&lt;Comment&gt; Comments { get; set; }
  }
  </code></pre>
  
  <p>Comment - class</p>
  
  <pre><code>public class Comment
      {
          public int CommentID { get; set; }
          public string Name { get; set; }
  
          [DataType(DataType.EmailAddress)]
          public string Email { get; set; }
  
          [DataType(DataType.MultilineText)]
          public string CommentBody { get; set; }
  
          public virtual int BlogID { get; set; } 
          public virtual Blog Blog { get; set; }
      }
  </code></pre>
  
  <p>BlogDetailViewModel</p>
  
  <pre><code>public class BlogDetailsViewModel
  {
      public Blog Blog { get; set; }
      public Comment Comment { get; set; }
  }
  </code></pre>
  
  <p>Blog - Details controller</p>
  
  <pre><code>public ViewResult Details(int id)
  {
  
      Blog blog = db.Blogs.Find(id);
      BlogDetailsViewModel viewModel = new BlogDetailsViewModel {Blog = blog};
      return View(viewModel);
  }
  </code></pre>
  
  <p>Blog Details - view</p>
  
  <pre><code>@model NPLHBlog.ViewModels.BlogDetailsViewModel
  </code></pre>
  
  <p>has code to display blogpost + comment form at end of blog details page below:</p>
  
  <pre><code>   @using (Html.BeginForm("Create", "Comment"))
      {
          &lt;input type="hidden" name="BlogID" value="@Model.Blog.BlogID" /&gt;
          &lt;div class="editor-label"&gt;
              @Html.LabelFor(model =&gt; model.Comment.Name)
          &lt;/div&gt;
          &lt;div class="editor-field"&gt;
              @Html.EditorFor(model =&gt; model.Comment.Name)
              @Html.ValidationMessageFor(model =&gt; model.Comment.Name)
          &lt;/div&gt;
  
          &lt;div class="editor-label"&gt;
              @Html.LabelFor(model =&gt; model.Comment.Email)
          &lt;/div&gt;
          &lt;div class="editor-field"&gt;
              @Html.EditorFor(model =&gt; model.Comment.Email)
              @Html.ValidationMessageFor(model =&gt; model.Comment.Email)
          &lt;/div&gt;            
  
          &lt;div class="editor-label"&gt;
              @Html.LabelFor(model =&gt; model.Comment.CommentBody)
          &lt;/div&gt;
          &lt;div class="editor-field"&gt;
              @Html.EditorFor(model =&gt; model.Comment.CommentBody)
              @Html.ValidationMessageFor(model =&gt; model.Comment.CommentBody)
          &lt;/div&gt;
          &lt;p&gt;
              &lt;input type="submit" value="Add Comment" /&gt;
          &lt;/p&gt;
  </code></pre>
  
  <p>comment - create controller</p>
  
  <pre><code>public class CommentController : Controller
  {
      private NPLHBlogDb db = new NPLHBlogDb();
  
      //
      // GET: /Comment/
  
      public ActionResult Create(Comment c)
      {
          Blog blog = db.Blogs.Single(b =&gt; b.BlogID == c.BlogID);
          blog.Comments.Add(c);
          db.SaveChanges();
          return RedirectToAction("Details", "Blog", new { ID = c.BlogID });
      }
  </code></pre>
  
  <p>Any help would be grateful.</p>