I'm using .net core MVC
I have loaded a dropdown with viewbag, but by default there is a selected value in the dropdownlist. I tried manually setting empty tag(<option selected="selected"></option>) but it didn't work still there another value getting selected.
Here is my code
@model Application.Services.PaginatedList<DataAccessViewModel>
@using System.Security.Claims;
@{
ViewData["Title"] = "Index";
}
@if (User.IsInRole("Admin")) {
<p>
<a asp-action="Create">Create New Config</a>
</p>
}
<form asp-action="Index" method="get">
<div class="form-actions no-color">
<p>
Manager Name: <select class="form-check-inline" style="width:200px" name="managerCode" asp-for="@Model.FirstOrDefault().ManagerCode" asp-items="@(new SelectList(@ViewBag.Managers,"ManagerCode", "ManagerName"))">
<option selected="selected"></option>
</select>
</p>
</div>
</form>
Note, If I remove asp-for="@Model.FirstOrDefault().ManagerCode", by default empty is getting loaded but if I choose a managercode and move to next page the chosen managercode doesn't persist in dropdown. So I guess it is something to do with asp-for="@Model.FirstOrDefault().ManagerCode"