I tried to Create and Edit one-to-many model in MVC ASP.net using visual studio 2013 web express and scaffolded CRUD control

I have class Family and class Member, where i have to create Family first, then edit the Family Data, and create member

Family class and Member class as following attributes:

 public class Family
                public int ID { get; set; }
                [Display(Name = "Family Name")]
                public string FamilyName { get; set; }
                public virtual ICollection<Member> Members { get; set; }

public class Member
            public int ID { get; set; }
            public int FamilyID { get; set; }
            [Display(Name = "Name")]
            public string MemberName { get; set; }

There was no problem in Family Edit and viewing the Member Index as Child in Family Edit

i Used following in Family Edit View :

<div class="row">
    <div class="col-md-offset-2 col-md-10">
        @{ Html.RenderAction("Index", "Members", new { id = Family.ID }); }

However, when i create new Member in Family Edit, Somehow i cant pass the ID of Family class as FamilyID in Members Class. Instead, it shows up as normal Int input form.

Im following this tutorial :


Do i miss something here?

*I could hide the input form of FamilyID in Member controller "Edit" View, but i couldnt figure out how to pass the ID of Family controller. I'm feeling like i'm forgetting the most basic things like parameter?

Thank you.

Edit 1 :

In create() of MemberController :

// GET: Members/Create
        public ActionResult Create()
            return View();

        // POST: Members/Create
        // To protect from overposting attacks, please enable the specific properties you want to bind to, for 
        // more details see http://go.microsoft.com/fwlink/?LinkId=317598.
        public ActionResult Create([Bind(Include = "ID,FamilyID,MemberName")] Member member)
            if (ModelState.IsValid)
                return RedirectToAction("Index");

            return View(riskIdentifier);

if im recall i need to insert a code like

FamilyID = Param1



But, how could i pass ID from Family class edit as Param1, so that it could be used to fill FamilyID from Member class?

Related posts

Recent Viewed