c# - Populate select box from database using MVC -
i creating website using asp.net , mvc. need populate select box values database , wondering how go doing this?
there many different ways it, do. in service class, db select & return selectlist object
public selectlist getasselectlist() { var depts = d in getall() select new { id = d.id, name = d.name }; return new selectlist(depts, "id", "name"); }
then in model, assign selectlist property:
model.suppliers = _supplierservice.getasselectlist(); return view(model);
and view:
@html.dropdownlistfor(model => model.deliverystoreid, model.deliverystores)
Comments
Post a Comment