I want to create an 'editable' table in MVC, where each row will have its own dropdownlist to update the row value. How do I set the dropdownlist selected value on page load for rows that were already updated before.
My current Razor code is like this:
<tbody>
@foreach (var conversion in Model.PaginatedConversions)
{
<tr>
<td>@conversion.tSystem.systemName</td>
<td>@conversion.conversionStandardValue</td>
<td>@Html.DropDownList("ConversionStandardIdFor" + conversion.conversionID.ToString(), Model.AvailableValuesForConversion, "")</td>
<td>@conversion.conversionDescription</td>
<td>@conversion.conversionDateInput</td>
<td>@conversion.ConversionDateConverted</td>
<td>@conversion.ConversionUser</td>
</tr>
}
But I cannot set the selected value of each dropdown. How can I do this? Thanks for the help!
Edit1 : This code loops a model property (Model.PaginatedConversions
), which is of type List<Conversion>
. The Conversion class is as followed:
public class Conversion {
int ConversionId { get;set; }
string ConversionValue { get; set; }
int ConversionConvertedValue { get; set; }
}
The goal of the table is to create editable rows for user to map the ConversionValue
to another value that can be selected in Model.AvailableConversionValues
. This converted value will be stored in ConversionConvertedValue
.
The property Model.AvailableConversionValues
are of type List<SelectListItem>
that contains the available values user can choose from to map the ConversionValue.