title: ASP.Net MVC 5 difficulty with addition object to db
body: <p>looking for help with my project. Trying to add object to db using input form. Here is my code:</p>
  
  <p>HomeController </p>
  
  <pre><code>   public class HomeController : Controller
      {   
          EventsContext db = new EventsContext();
  
          public ActionResult Index()
          {
              IEnumerable&lt;Event&gt; events = db.Events;
              ViewBag.Events = events;
              return View();
  
          }
          [HttpGet]
          public ActionResult CreateEvent()
          {
              return View();
  
          }
           [HttpPost]
          public ActionResult CreateEvent(AddEvent addEvent)
          {
              db.AddEvents.Add(addEvent);
              db.SaveChanges();
  
              return View("index");
          }
      }
  </code></pre>
  
  <p>At the moment I'm trying to hard code AddEventId and provide it within form, later I'll change it.
  Here is input form:</p>
  
  <pre><code>&lt;form method="post" action=""&gt;
              &lt;table&gt;
                  &lt;tr&gt;
                      &lt;td&gt;&lt;p&gt;Id :&lt;/p&gt;&lt;/td&gt;
                      &lt;td&gt;&lt;input type="text" name="AddEventId" /&gt; &lt;/td&gt;
                  &lt;/tr&gt;
                  &lt;tr&gt;
                      &lt;td&gt;&lt;p&gt;Title :&lt;/p&gt;&lt;/td&gt;
                      &lt;td&gt;&lt;input type="text" name="Title" /&gt; &lt;/td&gt;
                  &lt;/tr&gt;
                  &lt;tr&gt;
                      &lt;td&gt;&lt;p&gt;Date :&lt;/p&gt;&lt;/td&gt;
                      &lt;td&gt;&lt;input type="text" name="Date" /&gt; &lt;/td&gt;
                  &lt;/tr&gt;
                  &lt;tr&gt;
                      &lt;td&gt;&lt;p&gt;Time :&lt;/p&gt;&lt;/td&gt;
                      &lt;td&gt;&lt;input type="text" name="Time" /&gt; &lt;/td&gt;
                  &lt;/tr&gt;
                  &lt;tr&gt;
                      &lt;td&gt;&lt;p&gt;Address :&lt;/p&gt;&lt;/td&gt;
                      &lt;td&gt;&lt;input type="text" name="Location" /&gt;&lt;/td&gt;
                  &lt;tr&gt;
                      &lt;td&gt;&lt;p&gt;Lecturer:&lt;/p&gt;&lt;/td&gt;
                      &lt;td&gt;&lt;input type="text" name="Responsible" /&gt; &lt;/td&gt;
                  &lt;/tr&gt;                   
                  &lt;tr&gt;&lt;td&gt;&lt;input type="submit" value="Submit" /&gt; &lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;/tr&gt;
              &lt;/table&gt;
          &lt;/form&gt;
  </code></pre>
  
  <p>AddEvent class:</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Web;
  
  namespace PhClub.Models
  {
      public class AddEvent
      {        
          public int AddEventId { get; set; }
          public string Title { get; set; }
          public string Date { get; set; }
          public string Time { get; set; }
          public string Location { get; set; }
          public string Responsible { get; set; }
  
  
      }
  }
  </code></pre>
  
  <p>Event Class:</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Web;
  
  namespace PhClub.Models
  {
      public class Event
      {
          public int Id { get; set; }
          public string Title { get; set; }
          public string Date { get; set; }
          public string Time { get; set; }
          public string Location { get; set; }
          public string Responsible { get; set; }
      }
  }
  </code></pre>
  
  <p>It works ok with hard coded events </p>
  
  <pre><code>public class EventDbInitializer : DropCreateDatabaseAlways&lt;EventsContext&gt;
      {
          protected override void Seed(EventsContext db)
          {
              db.Events.Add(new Event { Title = "Name of Event", Date = "18/11/2017", Time = "20:00", Location = "Adress", Responsible = "Name" });
              db.Events.Add(new Event { Title = "Name of Event", Date = "03/03/2017", Time = "19:00", Location = "Adress", Responsible = "Name2" });
               //db.Events.Add(new Event { Title = "Title3, Date = "04/03/2017", Time = "217:00", Location = "School", Responsible = "Name"});
  
              base.Seed(db);
          }
      }
  </code></pre>
  
  <p>If i understand correctly after i press submit, CreateEvent post method should be used and all elements of Event object should be passed to create and Event in db. After that  it should be populated on the page. However, new events does not. What I'm not seeing? </p>