My table in db have fields : Id
,Organisation
,Info
.
I want make dropdowm list like that:
<select>
<option value='Id there'>'Organisation there'</option>...
I'm try to do it, using ViewBag:
ViewBag.Organisations = db.Organisations.ToList(); // get all fields from table using dbContext
and in View:
@Html.DropDownList('I don`t know what i shoud write here, please help')
How i can build dropdown list?
I recommend you to define a ViewModel for your page with a OrganisationId
property. Thus this value will be filled when selecting an entry of the organisations dropdown list.
@model BCO.Models.SelectOrganisationViewModel
@{
ViewBag.Title = "OrganisationInfo";
}
<div>
@Html.DropDownListFor(o => o.OrganisationId,
new SelectList(ViewBag.Organisations, "Id", "Name"))
</div>
The SelectList itself expects
as parameters.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With