c# - How to get the first item in a SelectList to be empty in ASP.NET MVC project? -
i have looked online solution, solutions have found applicable code has been implemented quite differently mine.
my dropdownlist populated list called selectionlist, populated in controller.
selectionlist= (db.items.tolist()) the view followed:
@html.label("selection:", htmlattributes: ...) <div class="col-md-3"> @html.dropdownlistfor(m => m.table.selectionid, new selectlist(model.selectionlist, "selectionid", "itemname"), new { @class = ... }) </div> there no issues displaying selectionlist, first item blank dropdownlist not display items.
any appreciated. :)
try this:
@html.dropdownlistfor(m => m.table.selectionid, new selectlist(model.selectionlist, "selectionid", "itemname"), "", new { @class = ... }) that third param empty string specifies option label.
Comments
Post a Comment