title: Insert 1 parent row and many child rows Asp.net MVC
body: <p>So I am creating a system where you can create forms and store them in the database which will be displayed for specific types of reports.</p>
  
  <p>On a report you will be entering 1 row into the Report table with the default report data like report owner, submission date, status etc</p>
  
  <p>On this same create page I would like to have all of the values from the created form that's stored in the DB, so far I have managed to get the displayed form to show correctly with the report. </p>
  
  <p>Each input for the form in the DB will be 1 entry into the ReportValues table.</p>
  
  <p>Currently I can get the Report from the Create View but the entries for ReportValue are not being returned to the Create Iaction.</p>
  
  <p>Please help :/</p>
  
  <p>Models:</p>
  
  <pre><code>public class Report
  {
      public Report()
      {
          //Set default Submission Date to the current date.
          this.SubmissionDate = DateTime.Now;
          this.Status = "New";
      }
  
      public int ID { get; set; }
  
      [ForeignKey("Form")]
      public int formID { get; set; }
  
      [StringLength(5, MinimumLength = 3)]
      public String Abreviation { get; set; }
  
      [Display(Name = "Submitted By")]
      public String Owner { get; set; }
  
  
      [RegularExpression(@"^[A-Z]+[a-zA-Z''-'\s]*$")]
      public String Category { get; set; }
  
      public String Status { get; set; }
  
      [DataType(DataType.Date), Display(Name = "Submit Date")]
      public DateTime SubmissionDate { get; set; }
  
      }
  }
  
      public class ReportValues
  {
      public int ID { get; set; }
      [ForeignKey("Report")]
      public int reportId { get; set; }
      public String title { get; set; }
      public String value { get; set; }
  }
  }
  
      public class FormReportViewModel
  {
      public Report Report { get; set; }
      public int reportID { get; set; }
      public String formCode { get; set; }
      public String abv { get; set; }
      public String category { get; set; }
      public IEnumerable&lt;ReportValues&gt; ReportValues { get; set; }
  }
  }
  </code></pre>
  
  <p>Create Iaction:</p>
  
  <pre><code>        // POST: Reports/Create
      [HttpPost]
      [ValidateAntiForgeryToken]
      public IActionResult Create(FormReportViewModel formReportViewModel)
      {
          Report r = formReportViewModel.Report;
          if (ModelState.IsValid)
          {
              _context.Report.Add(r);
              _context.SaveChanges();
              foreach (var item in formReportViewModel.ReportValues)
              {
                  ReportValues rv = new ReportValues { reportId = r.ID, title = item.title, value = item.value };
                  _context.ReportValues.Add(rv);
                  _context.SaveChanges();
              }
              return RedirectToAction("Index");
          }
  
          return View(formReportViewModel);
      }
  </code></pre>
  
  <p>View:</p>
  
  <pre><code>model IEnumerable&lt;FormReportViewModel&gt;
  @using System.Security.Claims;
  
  @{
  ViewData["Title"] = "Create";
  }
  
  &lt;h2&gt;Create&lt;/h2&gt;
  &lt;form asp-action="Create"&gt;
      &lt;div class="form-horizontal"&gt;
          &lt;h4&gt;Report&lt;/h4&gt;
          &lt;hr /&gt;
          &lt;div asp-validation-summary="ValidationSummary.ModelOnly" class="text-danger"&gt;&lt;/div&gt;
          &lt;div class="form-group"&gt;
              &lt;label asp-for="@Model.First().Report.Abreviation" class="col-md-2 control-label"&gt;&lt;/label&gt;
              &lt;div class="col-md-10"&gt;
                  &lt;input asp-for="@Model.First().Report.Abreviation" class="form-control" value="@Model.First().abv" readonly="readonly"/&gt;
                  &lt;span asp-validation-for="@Model.First().Report.Abreviation" class="text-danger" /&gt;
              &lt;/div&gt;
          &lt;/div&gt;
          &lt;div class="form-group"&gt;
              &lt;label asp-for="@Model.First().Report.Category" class="col-md-2 control-label"&gt;&lt;/label&gt;
              &lt;div class="col-md-10"&gt;
                  &lt;input asp-for="@Model.First().Report.Category" class="form-control" value="@Model.First().category" readonly="readonly"/&gt;
                  &lt;span asp-validation-for="@Model.First().Report.Category" class="text-danger" /&gt;
              &lt;/div&gt;
          &lt;/div&gt;
          &lt;div class="form-group"&gt;
              &lt;label asp-for="@Model.First().Report.Owner" class="col-md-2 control-label"&gt;&lt;/label&gt;
              &lt;div class="col-md-10"&gt;
                  &lt;input asp-for="@Model.First().Report.Owner" class="form-control" value=@User.GetUserName() readonly="readonly"/&gt;
                  &lt;span asp-validation-for="@Model.First().Report.Owner" class="text-danger" /&gt;
              &lt;/div&gt;
          &lt;/div&gt;
          &lt;div class="form-group"&gt;
              &lt;label asp-for="@Model.First().Report.Status" class="col-md-2 control-label"&gt;&lt;/label&gt;
              &lt;div class="col-md-10"&gt;
                  &lt;input asp-for="@Model.First().Report.Status" class="form-control" value="New" readonly="readonly"/&gt;
                  &lt;span asp-validation-for="@Model.First().Report.Status" class="text-danger" /&gt;
              &lt;/div&gt;
          &lt;/div&gt;
         @*Html.Raw(Model.First().formCode)*@
         @*
              The code below is from the Create ReportValues page    
         *@
          &lt;div class="form-group"&gt;
              &lt;label class="col-md-2 control-label" for="title"&gt;title&lt;/label&gt;
              &lt;div class="col-md-10"&gt;
                  &lt;input class="form-control" type="text" id="title" name="title" value="Animal Name" /&gt;
                  &lt;span class="text-danger field-validation-valid" data-valmsg-for="title" data-valmsg-replace="true" /&gt;
              &lt;/div&gt;
          &lt;/div&gt;
          &lt;div class="form-group"&gt;
              &lt;label class="col-md-2 control-label" for="value"&gt;value&lt;/label&gt;
              &lt;div class="col-md-10"&gt;
                  &lt;input class="form-control" type="text" id="value" name="value" value="" /&gt;
                  &lt;span class="text-danger field-validation-valid" data-valmsg-for="value" data-valmsg-replace="true" /&gt;
              &lt;/div&gt;
          &lt;/div&gt;
  
          &lt;div class="form-group"&gt;
              &lt;label class="col-md-2 control-label" for="title"&gt;title&lt;/label&gt;
              &lt;div class="col-md-10"&gt;
                  &lt;input class="form-control" type="text" id="title" name="title" value="Animal Weight" /&gt;
                  &lt;span class="text-danger field-validation-valid" data-valmsg-for="title" data-valmsg-replace="true" /&gt;
              &lt;/div&gt;
          &lt;/div&gt;
          &lt;div class="form-group"&gt;
              &lt;label class="col-md-2 control-label" for="value"&gt;value&lt;/label&gt;
              &lt;div class="col-md-10"&gt;
                  &lt;input class="form-control" type="text" id="value" name="value" value="" /&gt;
                  &lt;span class="text-danger field-validation-valid" data-valmsg-for="value" data-valmsg-replace="true" /&gt;
              &lt;/div&gt;
          &lt;/div&gt;
  
          &lt;div class="form-group"&gt;
              &lt;label class="col-md-2 control-label" for="title"&gt;title&lt;/label&gt;
              &lt;div class="col-md-10"&gt;
                  &lt;input class="form-control" type="text" id="title" name="title" value="Animal Colour" /&gt;
                  &lt;span class="text-danger field-validation-valid" data-valmsg-for="title" data-valmsg-replace="true" /&gt;
              &lt;/div&gt;
          &lt;/div&gt;
          &lt;div class="form-group"&gt;
              &lt;label class="col-md-2 control-label" for="value"&gt;value&lt;/label&gt;
              &lt;div class="col-md-10"&gt;
                  &lt;input class="form-control" type="text" id="value" name="value" value="" /&gt;
                  &lt;span class="text-danger field-validation-valid" data-valmsg-for="value" data-valmsg-replace="true" /&gt;
              &lt;/div&gt;
          &lt;/div&gt;
  
  
  
          &lt;div class="form-group"&gt;
              &lt;div class="col-md-offset-2 col-md-10"&gt;
                  &lt;input type="submit" value="Create" class="btn btn-default" /&gt;
              &lt;/div&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  &lt;/form&gt;
  
  
  
  
  &lt;div&gt;
      &lt;a asp-action="Index"&gt;Back to List&lt;/a&gt;
  &lt;/div&gt;
  </code></pre>