My Code:
public class EmpDb:DbContext
{
public DbSet<Parent> parents { get; set; }
public DbSet<GuestCheck> GuestChecks { get; set; }
}
public class Parent
{
[Key]
public string Name { get; set; }
public string Email { get; set; }
public bool? WillAttend { get; set; }
}
public class GuestCheck
{
[Key]
public string GuestName { get; set; }
public string GuestPhone { get; set; }
}
public class ParentModel
{
[Key]
[Required]
public List <Parent> parents { get; set; }
public List <GuestCheck> guc { get; set; }
}
Controller Page:
[HttpPost]
public ViewResult RsvpForm(Parent guestResponse)
{
try
{
if (ModelState.IsValid)
{
//// TODO: Email guestResponse to the part organizer
//return View("Thanks", guestResponse);
db.parents.Add(guestResponse);
db.SaveChanges();
}
//return RedirectToAction("RsvpForm","Home");
}
catch
{
return View();
}
return View();
}
View Page:
@model IEnumerable<demoapp.models.parentmodel>
@using (Html.BeginForm())
{
@Html.TextAreaFor(model => model.Parent.Name)
@Html.TextAreaFor(model => model.GuestCheck.GuestPhone)
@Html.TextAreaFor(modelItem => item.GuestCheck.GuestName)
@Html.TextAreaFor(modelItem => item.GuestCheck.GuestPhone)
<input type="submit" value="Submit" />
}
Showing this error
CS1061: 'System.Collections.Generic.IEnumerable<demoapp.Models.ParentModel>' does not contain a definition for 'Parent' and no extension method 'Parent' accepting a first argument of type 'System.Collections.Generic.IEnumerable<demoapp.Models.ParentModel>' could be found (are you missing a using directive or an assembly reference?)
Source Error:
Line 27:
Line 28:
Line 29: @Html.TextAreaFor(m=>Model.Parent.Name);
Line 30:
Line 31: }