you can use viewModel like this
public class PersonAddViewModel
{
public string Name{set;get;}
public List<string> Phones{set;get;}
}
on your form of your view you can add this code
@using (Html.BeginForm("Add", "Person", FormMethod.Post }))
{
<div class="col-md-6">
<div class="form-group">
@Html.LabelFor(p => p.Name)
@Html.EditorFor(p => p.Name, new { @class = "form-control" })
</div>
</div>
<div class="col-md-6" id="#row-0">
<div class="form-group">
@Html.LabelFor(p => p.Phones[0])
@Html.EditorFor(p => p.Phones[0], new { @class = "form-control" })
</div>
</div>
<div id=OtherPhones></div>
<button type="button" class="btn btn-danger btn-float btn-float-lg btn- rounded" id="add"><i class="icon-plus2"></i></button>
<button type=submit>Submit</button>
}
then add this jquery script to your page
$("#add").click(function () {
inputCount++;
var newDiv = $("#row-0").clone();
newDiv.attr('id', 'row-' + inputCount);
newDiv.find("input,select").each(function () {
$(this).attr({
'name': function (_, name) { return name.toString().replace('0', inputCount) },
'id': function (_, id) { return id.toString().replace('0', inputCount) },
'item': function (_, item) { return item.toString().replace('0', inputCount) }
});
var type = $(this).attr('type');
if (type === 'hidden') {
$(this).val('0');
} else {
$(this).val('');
}
});
newDiv.find(".available").each(function () {
$(this).attr({
'id': function (_, id) { return id.toString().replace('0', inputCount) }
});
});
newDiv.find(".delCol").each(function () {
$(this).find('button').attr('item', inputCount);
$(this).fadeIn();
});
newDiv.find("label").each(function () {
$(this).attr({
'for': function (_, id) { return id.toString().replace('0', inputCount) }
});
});
newDiv.find(".field-validation-valid").each(function () {
$(this).attr({
'data-valmsg-for': function (_, id) { return id.toString().replace('0', inputCount) }
});
}).end();
$("#Other").append(newDiv);
$('form').data('validator', null);
$.validator.unobtrusive.parse('form');
});