I have a table that has DropDownList inside it. The DropDownList has values like this :
This is Test1
This is Test2
This is Test3
This is Test4
This is Test5
There is another row in the table that says Test1 or Test2 and so on.
Please see below table:
In the above table, if the first column says "Test1", I want the DropDownList to pre select "This is test1".
If the first column says "Test3" then I want the DropDownList to select the text "This is Test3".
View
<table class="table table-bordered">
<thead>
<tr>
<th>FileName</th>
<th>Type</th>
<th>Record Date</th>
</tr>
</thead>
<tbody>
@if (Model != null)
{
@foreach (var item in Model)
{
<tr>
<td>
<td>
<label id="lblName_@item.DocumentId">@item.Name</label>
</td>
<td>
<select class="form-control" style="min-width:150px" id="ddldoc_@item.DocumentId" asp-for="@item.DocumentType" asp-items="ViewBag.DocumentType"></select>
</td>
</tr>
}
}
</tbody>
Below is my controller code.
public IActionResult Index()
{
ViewData["DocumentType"] = new
SelectList(docTypes, "Id", "Description");
}