How to Insert Multiple Rows in One Table? (MVC 5 ASP.NET)
<p>I would want to insert multiple entries in my table called 'sibling' using it's Create Method (which I generated automatically using Scaffolding methods). I already made the form dynamic in adding the fields. However, when I click on the Submit button it only gets the first entry.</p>

<p>I sort of have an idea by implementing 'foreach' in the said method but I can't seem to find an answer that is spot on. Especially for my case I just want to modify the Create Method for 'sibling' which was generated automatically (if there is such a way without having to create a new method - but if not I am fine with a different approach as well).</p>

<p>This is my SiblingController:</p>

<pre><code>public ActionResult Create(int id)
    {
        var sib = new sibling();
        sib.child_id = id;
        return View(sib);
    }

    [HttpPost]
    [ValidateAntiForgeryToken]

    public ActionResult Create([Bind(Include = "sibling_id,child_id,age,gender")] sibling sibling)
    {
        if (ModelState.IsValid)
        {
            db.siblings.Add(sibling);
            db.SaveChanges();
            return RedirectToAction("Index");
        }

        ViewBag.child_id = new SelectList(db.children, "child_id", "last_name", sibling.child_id);
        return View(sibling);
    }
</code></pre>

<p>This is my Create.cshtml for Sibling:</p>

<pre><code>@model dummyApp.Schema.TestModels.sibling

@{
ViewBag.Title = "Create";
}

@section Scripts{
&lt;script type="text/javascript"&gt;
    //Coding

    $("#numBox").change(function () {
        var htmlString = "";
        var len = $(this).val();
        for (var i = 0; i &lt; len; i++) {

            htmlString += ' &lt;div class="form-group"&gt;\
                                @Html.LabelFor(model =&gt; model.child_id, "child_id", htmlAttributes: new { @class = "control-label col-md-2" })\
                                &lt;div class="col-md-10"&gt;\
                                    @Html.EditorFor(model =&gt; model.child_id, new { htmlAttributes = new { @class = "form-control" }})\
                                    @Html.ValidationMessageFor(model =&gt; model.child_id, "", new { @class = "text-danger" })\
                                &lt;/div&gt;\
                            &lt;/div&gt;\
                            &lt;div class="form-group"&gt;\
                                @Html.LabelFor(model =&gt; model.age, htmlAttributes: new { @class = "control-label col-md-2" })\
                                &lt;div class="col-md-10"&gt;\
                                    @Html.EditorFor(model =&gt; model.age, new { htmlAttributes = new { @class = "form-control" } })\
                                    @Html.ValidationMessageFor(model =&gt; model.age, "", new { @class = "text-danger" })\
                                &lt;/div&gt;\
                            &lt;/div&gt;\
                            &lt;div class="form-group"&gt;\
                                @Html.LabelFor(model =&gt; model.gender, htmlAttributes: new { @class = "control-label col-md-2" })\
                                &lt;div class="col-md-10"&gt;\
                                    @Html.EditorFor(model =&gt; model.gender, new { htmlAttributes = new { @class = "form-control" } })\
                                    @Html.ValidationMessageFor(model =&gt; model.gender, "", new { @class = "text-danger" })\
                                &lt;/div&gt;\
                            &lt;/div&gt;\
                        ';
        }
        $("#adtnl_fields").html(htmlString);
    })
&lt;/script&gt;
}
&lt;h2&gt;Create&lt;/h2&gt;

@using (Html.BeginForm()) 
{
@Html.AntiForgeryToken()

&lt;div class="form-horizontal"&gt;
    &lt;h4&gt;sibling&lt;/h4&gt;
    &lt;hr /&gt;
    @Html.ValidationSummary(true, "", new { @class = "text-danger" })
    &lt;!--
    &lt;div class="form-group"&gt;
        @Html.LabelFor(model =&gt; model.sibling_id, htmlAttributes: new { @class = "control-label col-md-2" })
        &lt;div class="col-md-10"&gt;
            @Html.EditorFor(model =&gt; model.sibling_id, new { htmlAttributes = new { @class = "form-control" } })
            @Html.ValidationMessageFor(model =&gt; model.sibling_id, "", new { @class = "text-danger" })
        &lt;/div&gt;
    &lt;/div&gt;
    --&gt;
    &lt;div class="form-group"&gt;
        @Html.Label("Number of Siblings:", htmlAttributes: new { @class = "control-label col-md-2" })
        &lt;div class="col-md-10"&gt;
            &lt;input type="number" id="numBox" class="form-control"/&gt;
        &lt;/div&gt;
    &lt;/div&gt;

    &lt;!--
    &lt;div class="form-group"&gt;
        @Html.LabelFor(model =&gt; model.child_id, "child_id", htmlAttributes: new { @class = "control-label col-md-2" })
        &lt;div class="col-md-10"&gt;
            @*Html.DropDownList("child_id", null, htmlAttributes: new { @class = "form-control" })*@
            @Html.EditorFor(model =&gt; model.child_id, new { htmlAttributes = new { @class = "form-control" }})
            @Html.ValidationMessageFor(model =&gt; model.child_id, "", new { @class = "text-danger" })
        &lt;/div&gt;
    &lt;/div&gt;

    &lt;div class="form-group"&gt;
        @Html.LabelFor(model =&gt; model.age, htmlAttributes: new { @class = "control-label col-md-2" })
        &lt;div class="col-md-10"&gt;
            @Html.EditorFor(model =&gt; model.age, new { htmlAttributes = new { @class = "form-control" } })
            @Html.ValidationMessageFor(model =&gt; model.age, "", new { @class = "text-danger" })
        &lt;/div&gt;
    &lt;/div&gt;

    &lt;div class="form-group"&gt;
        @Html.LabelFor(model =&gt; model.gender, htmlAttributes: new { @class = "control-label col-md-2" })
        &lt;div class="col-md-10"&gt;
            @Html.EditorFor(model =&gt; model.gender, new { htmlAttributes = new { @class = "form-control" } })
            @Html.ValidationMessageFor(model =&gt; model.gender, "", new { @class = "text-danger" })
        &lt;/div&gt;
    &lt;/div&gt;
    --&gt;

    &lt;!-- Div for additional fields --&gt;
    &lt;div id="adtnl_fields"&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;div&gt;
    @Html.ActionLink("Back to List", "Index")
&lt;/div&gt;
</code></pre>

<p>This is my 'sibling.cs':</p>

<pre><code>public partial class sibling
{
    public int sibling_id { get; set; }
    public int child_id { get; set; }
    public Nullable&lt;int&gt; age { get; set; }
    public string gender { get; set; }

    public virtual child child { get; set; }
}
</code></pre>

<p>Please help. Thank you!</p>