Click here to Skip to main content
15,891,513 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
My Code:

public class EmpDb:DbContext
{
public DbSet<Parent> parents { get; set; }
public DbSet<GuestCheck> GuestChecks { get; set; }

}

SQL
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:

SQL
[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
XML
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:  }
Posted
Updated 30-Jan-14 22:46pm
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900