Create a dropdownlist from datatable

I want to create a dropdownlist based on a table with values from my Table_Services anda save in my Table_Status Services

IMG

at the moment I have this:

@Html.TextBoxFor(m => @item.Status, new { @class = "Status", disabled = true }) //from my Table_Status

i try to create a list, but without success :(

My model:

public List<Table_Services> ServicesList { get; set; }

Controller:

OrderViewModel model = new OrderViewModel
        {
            ServicesList = db.Table_Services.ToList()
        };

View:

@Html.DropDownListFor(m => @item.Status, new SelectList(Model.ServicesList, "Services", "Select", new { @class="statusselect",disabled = true })

Thanks,

1 answer

  • answered 2021-01-19 10:13 MD. RAKIB HASAN

    You missed dataValueField on Html.DropDownListFor

    @Html.DropDownListFor(model => @item.Status, new SelectList(Model.ServicesList, "ID", "Services", "Select One"), new { @class = "form-control col-md-12" })