I have the following form that contains data in a multi-dimensional array that I want to send to my server. The problem is I can't see to pick this data up in my controller.
index.html
<form id="my-form" action="/Home/TestingMethod" method="post">
<table id="people" class="table table-striped">
<thead>
<tr>
<th>ID</th>
<th>Name</th>
<th>Owns Item</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>Danny</td>
<td class="items">
<select name="PersonList[1]Item[]" class="form-control">
<option value=""></option>
<option value="Keys">Keys</option>
<option value="Phone">Phone</option>
</select>
</td>
</tr>
</tbody>
</table>
</form>
MyModel
public class MyModel
{
public List<int> PersonList { get; set; }
}
HomeController
[HttpPost]
public JsonResult TestingMethod(MyModel model)
{
List<int> list_of_people = model.PersonList;
return Json("I am the server, I got your data.");
}
The issue is that list_of_people
contains 0 elements.
Form data submitted
PersonList[1]Item[]:Phone
related: how to access Javascript multidimensional array in MVC controller