My table in db have fields : Id
,Organisation
,Info
.
I want make dropdowm list like that:
controller
ViewBag.category = new SelectList(db.CategoryMasters.ToList(), "CategoryId", "CategoryName");
view
@Html.LabelFor(model => model.CategoryId, htmlAttributes: new { @class = "control-label col-md-2" })
@Html.EditorFor(model => model.CategoryId, new { htmlAttributes = new { @class = "form-control", id = "categoryid" } })
@Html.DropDownList("select", ViewBag.category as SelectList, new { @id = "category" })
@Html.ValidationMessageFor(model => model.CategoryId, "", new { @class = "text-danger" })
JS