If your initial list is empty and it's to be dynamically clreated, you don't need to pass empty list to the view. here goes simplified version of what you need.
controller:
public class TestController : Controller
{
// GET: Test
public ActionResult Index()
{
return View();
}
[HttpGet]
public ActionResult AddTeams()
{
// you do not need to pass anything if you list is empty
return View();
}
[HttpPost]
public ActionResult AddTeams(List<string> teamNames)
{
// do whatever you want with your teamnames
return RedirectToAction("Index");
}
}
view:
@using (Html.BeginForm("AddTeams", "Test", FormMethod.Post))
{
<table id="teams-list">
<tr>
<td>Team name:</td>
<td><input type="text" name="teamNames[0]" /></td>
</tr>
</table>
<button type="button" id="add-btn">Add one more team</button>
<br/>
<button type="submit">submit</button>
}
<script>
$('#add-btn').on('click', function() {
var currentTeamCount = $('#teams-list tr').length;
$('#teams-list tr:last').after('<tr><td>Team name:</td><td><input type="text" name="teamNames[' + currentTeamCount + ']" /></td></tr>');
});
</script>