In the Controller, we have to write the code in the below way :-
List<OrganisationTypes> organisationTypes = new List<OrganisationTypes>();
OrganisationRepository organisationRepository = new OrganisationRepository ();
using (var dbcontext = new OrganisationContext())
{
organisationTypes = dbcontext.OrganisationTypes.ToList();
var selectList = new SelectList(organisationTypes, "OrganisationId", "OrganisationName" );
ViewBag.OrganisationTypes = selectList;
}
In the View, we have to mention in the below way:-
@Html.DropDownListFor(model => model.OrganisationId,
(IEnumerable<SelectListItem>)ViewBag.OrganisationTypes, new { @class = "form-control"
})
No comments:
Post a Comment