this is my controller:
public ActionResult Create() {
Number newNumber = new Number();
return View(newNumber);
}
and View :
@model PhoneBook.Models.Number
@{
ViewBag.Title = "Create";
}
<h2>Create</h2>
<script src="../../Scripts/jQuery.AddNewNumber.js" type="text/javascript"></script>
@using (Html.BeginForm()) {
@Html.ValidationSummary(true)
@Html.HiddenFor(model => model.Contact.Id)
<fieldset>
<legend>Number</legend>
<div class="TargetElements">
<div class="editor-label">
@Html.LabelFor(model => model.PhoneNumber)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.PhoneNumber)
@Html.ValidationMessageFor(model => model.PhoneNumber)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.NumberKind)
</div>
<div class="editor-field">
@Html.DropDownListFor(model => model.NumberKind.Title, NumberKinds)
</div>
</div>
<p>
<input class="AddNew" value="Add New" type="button" /></p>
<p>
<input type="submit" value="Create" />
</p>
</fieldset>
}
By press AddNew button (use jQuery AddNewNumber.js) new input+DropDown Added to form in client side. this is script:
$(document).ready(function () {
$('.AddNew').click(function () {
var targetcloneelements = $(".TargetElements:first").clone();
targetcloneelements.find('input').val('');
targetcloneelements.insertAfter('.TargetElements:last');
});
});
This way(Add new) is very usual, All of us can see that in many sites (So that must have a solution), But there is a problem in retrieve values. When I have one entry element(include input+DropDown) I can retrieve values like the following in post of my controller:
[HttpPost]
public ActionResult Create(Number NewNumber, FormCollection collection) {
db.Numbers.Add(NewNumber);
db.SaveChanges();
return RedirectToAction("Index")
}
I read this articles : 1 , 2 , 3 but none of them haven’t any solution for fly mode add entries, when I know the numbers of entity it can be possible but in fly mode it can be 1 or 1000
So, is there any way to retrieve values and add them to DataBase?
Edit:
I find the values in FormCollection but yet I don’t know how extract them from collection? This is a picture of the Collection values in breakponit of binding

Edit2:
Find to retrieve all values: (every element has a key that seen in above pic)
string[] PhoneNumbers = collection.GetValues("PhoneNumber");
every element has a key so you can use this for example: