My Model
public class Person
{
public int Id { get; set; }
public string Name { get; set; }
}
My Controller
public class PersonController : Controller
{
// GET: Home
public ActionResult Index()
{
return View();
}
[HttpPost]
public ActionResult Save(Person[] people)
{
foreach (var p in people)
// Do Something
return View();
}
}
My View
@using (Html.BeginForm("Save", "Person", FormMethod.Post))
{
<div id="form"></div>
<button type="button" class="btn btn-info" id="addItem">New Person</button>
<button type="submit" class="btn btn-success">Salvar</button>
}
My Script
<script type="text/javascript">
$(document).ready(function () {
$("#addItem").click(addField);
addField();
});
function addField() {
var html = "Name: <input type='text' name='people[]' />";
$("#form").append(html);
}
</script>
I need to post the inserted data from forms to controller, but dont work... how can i do that?
i read about binding to model arrays and i did this above.