title: Passing ID from one view to another and storing it in another table
body: <p>I have a create page for adding a festival and a page for a user to create an event for that festival. I am trying to pass the festivals id from and store it in my events table. It gets caught on the post back of the create page. Here is the code:</p>
  
  <p>Controller:</p>
  
  <pre><code>[HttpGet]
      public ActionResult Create2(int festID)
      {
          EventsVM events = new EventsVM { festivalID = festID };
  
          events.eType = db.EType.ToDictionary(p =&gt; p.ID, q =&gt; q.EType);
          events.eType.Add(-1, "----- Add New Event Type -----");
  
          events.eventsDate = DateTime.Now;
          events.startTime = DateTime.Now;
          events.endTime = DateTime.Now;
  
          return View(events);
      }
  
      [HttpPost]
      [ValidateAntiForgeryToken]
      public ActionResult Create2(EventsVM model)
      {
          if (ModelState.IsValid != true)
          {
              if (model.selectedEType != -1)
              {
                  //db.save stuff from create.
                  Events Newevent = new Events();
                  Newevent.EndTime = model.endTime;
                  Newevent.StartTime = model.startTime;
                  Newevent.EventsDate = model.eventsDate = DateTime.Now;
                  Newevent.EventsName = model.EventsName;
                  Newevent.EType = db.EType.Where(p =&gt; p.ID == model.selectedEType).Single();
                  Newevent.Location = model.Location;
                  //Caught here!!!
                  Newevent.FestivalID = model.festivalID;
  
                  db.Events.Add(Newevent);
                  db.SaveChanges();
                  return RedirectToAction("Details", "Festival", new { id = model.festivalID });
                  //return RedirectToAction("Index", "Festival");
                  //return RedirectToAction("Index", "Events");
                  //String test = "test3";
              }
              ModelState.AddModelError("", "No Event Type Picked");
          }
  
          model.eType = db.EType.ToDictionary(p =&gt; p.ID, q =&gt; q.EType);
          model.eType.Add(-1, "----- Add New Event Type -----");
          model.eventsDate = DateTime.Now;
          model.startTime = DateTime.Now;
          model.endTime = DateTime.Now;
  
          return View(model);
      }
  </code></pre>
  
  <p>I have to "saved" Festival ID on the details page of the selected festival id</p>
  
  <p>Details.cshtml - Festival</p>
  
  <pre><code> &lt;div&gt;
  &lt;h3&gt;Details for Festival: @Model.FestivalName.ToString()&lt;/h3&gt;
  &lt;/div&gt;
  &lt;hr /&gt;
  &lt;div class="table-responsive"&gt;
  &lt;!--&lt;div class="table"&gt;--&gt;
      &lt;table class="table"&gt;
          &lt;tr&gt;
              &lt;th&gt;
                  Festival Name
              &lt;/th&gt;
              &lt;th&gt;
                  Start Date
              &lt;/th&gt;
              &lt;th&gt;
                  End Date
              &lt;/th&gt;
              &lt;th&gt;
                  Town
              &lt;/th&gt;
              &lt;th&gt;
                  County
              &lt;/th&gt;
              &lt;th&gt;
                  Festival Type
              &lt;/th&gt;
              &lt;th&gt;
                  Options
              &lt;/th&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
                  @Html.DisplayFor(model =&gt; model.FestivalName)
              &lt;/td&gt;
              &lt;td&gt;
                  @Html.DisplayFor(model =&gt; model.StartDate)
              &lt;/td&gt;
              &lt;td&gt;
                  @Html.DisplayFor(model =&gt; model.EndDate)
              &lt;/td&gt;
              &lt;td&gt;
                  @Html.DisplayFor(model =&gt; model.FestivalTown.Name)
              &lt;/td&gt;
              &lt;td&gt;
                  @Html.DisplayFor(model =&gt; model.FestivalCounty.Name)
              &lt;/td&gt;
              &lt;td&gt;
                  @Html.DisplayFor(model =&gt; model.FType.FType)
              &lt;/td&gt;
              &lt;td&gt;
                  &lt;div class="btn-group"&gt;
                      @*                        &lt;button class="btn btn-info btn-sm dropdown-toggle" type="button" data-toggle="dropdown"&gt;Options&lt;/button&gt;*@
                      &lt;button type="button" class="btn btn-info btn-sm dropdown-toggle" data-toggle="dropdown"&gt;
                          &lt;span class="caret"&gt;&lt;/span&gt;
                      &lt;/button&gt;
                      &lt;ul class="dropdown-menu"&gt;
                          &lt;li role="presentation" class="dropdown-header"&gt;Festival&lt;/li&gt;
                          &lt;li&gt;@Html.ActionLink("Edit", "Edit2", new { id = Model.FestivalId })&lt;/li&gt;
                          &lt;li&gt;@Html.ActionLink("Back to List", "Index")&lt;/li&gt;
                      &lt;/ul&gt;
                  &lt;/div&gt;
              &lt;/td&gt;
          &lt;/tr&gt;
      &lt;/table&gt;
  &lt;/div&gt;
  @if (Model.Events != null)
  {
      &lt;center&gt;&lt;div class="well well-sm" style="width:400px"&gt;@Model.FestivalName.ToString() has @Model.Events.Count() Events&lt;/div&gt;&lt;/center&gt;
      @Html.ActionLink("Add Event", "Create2", "Events", new { festID = Model.FestivalId }, new { @class = "btn btn-primary"})
      &lt;br /&gt;
      &lt;br /&gt;
      &lt;!--&lt;div class="table-responsive"&gt;--&gt;
      &lt;div class="table"&gt;
          &lt;table class="table table-striped"&gt;
              &lt;tr&gt;
                  &lt;th&gt;Events Name
                  &lt;/th&gt;
                  &lt;th&gt;Events Date
                  &lt;/th&gt;
                  &lt;th&gt;Start Time
                  &lt;/th&gt;
                  &lt;th&gt;End Time
                  &lt;/th&gt;
                  &lt;th&gt;Options
                  &lt;/th&gt;
              &lt;/tr&gt;
  
              @foreach (var e in Model.Events)
              {
                  &lt;tr&gt;
                      &lt;td&gt;
                          @Html.DisplayFor(modelItem =&gt; e.EventsName)
                      &lt;/td&gt;
                      &lt;td&gt;
                          @Html.DisplayFor(modelItem =&gt; e.EventsDate)
                      &lt;/td&gt;
                      &lt;td&gt;
                          @Html.DisplayFor(modelItem =&gt; e.StartTime)
                      &lt;/td&gt;
                      &lt;td&gt;
                          @Html.DisplayFor(modelItem =&gt; e.EndTime)
                      &lt;/td&gt;
                      &lt;td&gt;
                          &lt;div class="btn-group"&gt;
                              &lt;button type="button" class="btn btn-success btn-sm dropdown-toggle" data-toggle="dropdown"&gt;
                                  &lt;span class="caret"&gt;&lt;/span&gt;
                              &lt;/button&gt;
                              &lt;ul class="dropdown-menu"&gt;
                                  &lt;li role="presentation" class="dropdown-header"&gt;Event&lt;/li&gt;
                                  &lt;li role="presentation" class="divider"&gt;&lt;/li&gt;
                                  &lt;li&gt;@Html.ActionLink("Edit", "Edit2", "Events", new { id = e.ID }, null)&lt;/li&gt;
                                  &lt;li&gt;@Html.ActionLink("Details", "Details", "Events", new { id = e.ID }, null)&lt;/li&gt;
                                  &lt;li&gt;@Html.ActionLink("Delete", "Delete", "Events", new { id = e.ID }, null)&lt;/li&gt;
                              &lt;/ul&gt;
                          &lt;/div&gt;
                      &lt;/td&gt;
                  &lt;/tr&gt;
              }
  
          &lt;/table&gt;
      &lt;/div&gt;  
  }
  </code></pre>
  
  <p>The error I get is when it posts back, the id in the link becomes a 0, so its not saving the id. Any id on how I can fix this?</p>