I have a List view like this:
@model List<ABC.Models.InfoDetails>
I use a for loop to display the values in a table in order to be able to edit each row and use a submit button (at the bottom of the table) to post the data back to the controller.
@using (Html.BeginForm("UpdateUsers", "User")) {
<table ...
<tbody>
@for (var i = 0; i < Model.Count(); i++) {
...
}
The values are posted back like this:
[0].Title
[1].Title
etc.
This is fine and I get the correct values in the controller.
The only problem I have is posting the selected value from a select2 dropdown element of each row.
<select class="js-select2 form-control" name="user" id="select2-user">
The name value ("user") is posted to the controller instead of the name [0].User
My Javascript:
var users = [
{ id: '0', text: 'Please choose...' },
{ id: '1', text: 'Paul' }
];
$("[name='user']").select2({
placeholder: "Select a user",
data: users
});
Is there any way to put the value to the according index of each user property?
I hope you can help me.