I have problem with my code. I select a specific value using SelectList
function but it seems it is not working. Here is my code:
Controller:
Public IActionResult Index()
{
myList.loanFrequency = new SelectList(lstLoanFrequency, "Id", "Value", 4);
}
View:
<div class="form-group">
<label>Loan Frequency</label>
<select class="form-control" asp-for="loanContract.LoanFrequencyId" asp-items="@Model.loanFrequency" disabled></select>
<small class="form-text text-muted">Upon registration to this loan you are set to a <b>Biweekly</b> because your payroll mostly computed and deducted every Biweekly day of the month.</small>
</div>
And it seems it renders like this:
<select class="form-control" disabled="" data-val="true" data-val-required="The LoanFrequencyId field is required." id="loanContract_LoanFrequencyId" name="loanContract.LoanFrequencyId">
<option value="1">Weekly</option>
<option value="2">Biweekly</option>
<option value="3">Semimonthly</option>
<option value="4">Monthly</option>//Not rendered in HTML
<option value="5">Bimonthly</option>
<option value="6">Quarterly</option>
<option value="7">Semiannually</option>
<option value="8">Annually</option>
</select>
And since I set the SelectedValue
from SelectList method it should suppose to be render the item something like this:
<select class="form-control" disabled="" data-val="true" data-val-required="The LoanFrequencyId field is required." id="loanContract_LoanFrequencyId" name="loanContract.LoanFrequencyId">
<option value="1">Weekly</option>
<option value="2">Biweekly</option>
<option value="3">Semimonthly</option>
<option value="4" selected>Monthly</option>//This should be rendered in the HTML
<option value="5">Bimonthly</option>
<option value="6">Quarterly</option>
<option value="7">Semiannually</option>
<option value="8">Annually</option>
</select>
How come that It didn't select a specific value? Can someone help me with this?