c# - Id not coming in dropdown using viewbag -
i trying dropdown list in application, name of dropdown coming can't track id of user it.
i tried doing way-
controller-
public actionresult _dropdown() { var list = (from u in db.users select new { u.name, u.id }).tolist(); viewbag.uname = new selectlist(list, "id", "name"); return partialview(); }
method-
@model registration.user @html.dropdownlist("name", new selectlist(viewbag.uname, "id", "name"))
i getting "id" not found error , when replacing name same name also.
how resolve issue?
note-
i populate names , id should of selected item. can't attach id dropdown list.
try this:
viewbag.uname = new selectlist(list, "id", "name");
and in view:
@html.dropdownlistfor(model => model.yourmodel, (selectlist)viewbag.uname, "--select--")
Comments
Post a Comment