I have this in my form as shown below:
<div class="col-lg-3">
<label class="form-label" asp-for="WOHeader.SP_ID">@CommonResource.SalesPerson *</label>
<select class="form-select" asp-for="WOHeader.SP_ID" asp-items='(IEnumerable<SelectListItem>)ViewData["SPList"]!' asp-disabled="@(Model.REC_MODE == (short)RecModeId.AddNew)">
</select>
<span class="invalid-feedback" asp-validation-for="WOHeader.SP_ID"></span>
</div>
I can get the selected value binded to WOHeader.SP_ID. I also need to get its selected text. The best option I can think of right now is to save it to a hidden field.
Is there any better way to get both the selected value and text in code-behind after a post-back via Ajax? I have tried various ways but didn't work.
Please advise. Thanks.
If you need post the selected value and text to backend, hidden input should be a better way. Just be sure the name match the model property and submit the button.
For ajax, it may not easy to get the element value and you need post with antiforeign token. Any way it depends on your real scenario.
A simple working demo:
Page
Bakcend