I just want to insert a collection of phone numbers for each employee into the employee table. I know how to do this in the user interface (client side java script) I need a specific code (when I increase the number of phones on the client side, increase the size of objects from the phone like
I read this:
http://www.itorian.com/2013/04/nested-collection-models-in-mvc-to-add.html
everything is fine, but when I increase the number of phones in the user interface by more than two, just insert 2 rows into the database because of this: my entry point
public ActionResult Add()
{
var Employee = new employee();
Employee.CreatePhoneNumbers(2);
return View(Employee);
}
[HttpPost]
public ActionResult Add(employee emp) {
if (ModelState.IsValid) {
telephoneEntities db = new telephoneEntities();
foreach(phon phone in emp.phons.ToList()) {
if (phone.deletephon == true) {
emp.phons.Remove(phone);
}
}
db.employees.Add(emp);
db.SaveChanges();
return RedirectToAction("Index", "Home");
}
return View();
}
I need javascript to change this value to 2 or 3 .... (phone number added in user interface)
thanks