Base solution for your next web application
Open Closed

[SOLVED]Edit Modal - Dropdownlist not showing selected value #2052


User avatar
0
exlnt created

In my custom entity edit modal view, I have a dropdownlist to select currency code. The dropdown is getting bound with all the values just fine. However, the dropdown is not showing the selected value on the record being edited, instead it always shows the seed value?

This is my controller method for EditModal:

public async Task<PartialViewResult> EditModal(int id)
        {
            var companyEditDto = await _companyAppService.GetCompanyForEdit(new EntityDto(id));
            var currencyCodes = _listValuesAppService.GetListValuesComboboxItems("CurrencyCode");
            var viewModel = new EditCompanyViewModel(companyEditDto, currencyCodes);
            return PartialView("_EditModal", viewModel);
        }

This is my CSHTML for my dropdown:

@Html.DropDownList("CurrencyCode", Model.CurrencyCodes.Select(i => i.ToSelectListItem()), new { @class = "form-control edited"})

Here is the rendered output of my edit modal: [attachment=0:3d74sk3g]Screenshot (36).png[/attachment:3d74sk3g]


3 Answer(s)
  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    You need to set IsSelected of a menuItem to true. You can do it in GetListValuesComboboxItems method of ListValuesAppService or you can do it after retrieving currencyCodes from _listValuesAppService.GetListValuesComboboxItems("CurrencyCode").

  • User Avatar
    0
    exlnt created

    <cite>ismcagdas: </cite> Hi,

    You need to set IsSelected of a menuItem to true. You can do it in GetListValuesComboboxItems method of ListValuesAppService or you can do it after retrieving currencyCodes from _listValuesAppService.GetListValuesComboboxItems("CurrencyCode").

    Thanks, that helped! I was able to get it working now.

  • User Avatar
    0
    ismcagdas created
    Support Team

    That's good :)