i need to get value of many select list with one name in asp.net core
I fill in a table using the loop and display it. The thing is that in each row of the table there is a series of item in select lists that have fixed values that are filled for each row of the table.
And the next thing is that when posting the page, I need to know what value the user has selected in each row from the select list item
That means I need both the table row number and the value selected.
The main problem is that these select lists of items are also names, I can not give a name for each, because I do not have other names when taking it back
Thanks for telling me how I can fix this
<tbody>
@foreach (var item in allQuestion)
{
<tr>
<td>@item.Question_Title</td>
<td>@item.Answere1</td>
<td>@item.Question_type</td>
<td>
<select id="trueRate[@item.Question_ID]" class="form-control">
@foreach (var rate in TrueRate)
{
<option value="@rate.Value">@rate.Text</option>
}
</select>
</td>
</tr>
}
</tbody>
Maybe I explained badly. I want to create an array from a list of numbers. This array must be repeated in each row of the table , And the user selects a value from this list for each row of the table. Now my problem is that I do not know how to create this array so that its name is available to me and the next problem is that I do not know how to get the value of the code. Keep in mind that this list of numbers is repeated for each row of the table and I need them all on the code side.
Actually, There is some difficulty in understanding your needs. But From your question and code, I guess you want to use
foreach()to traverse your model, Then in each item, you want to nest a dropdown list, So i write a simple demo here, Hope it is what you want.Model
Controller
View
Demo:
Then you can see it get the value of what you selected successfully.