Reputation: 4733
ViewBag.partners = new SelectList(db.PRT_PARTNERS, "ID", "FIRST_NAME", "LAST_NAME");
db is my database object
PRT_PARTNERS is the table
ID is the field which must select
and FIRST_NAME is the field which will text in dropdownlist
can i populate it like this?
ViewBag.partners = new SelectList(db.PRT_PARTNERS, "ID", "FIRST_NAME + LAST_NAME");
Upvotes: 0
Views: 266
Reputation: 62488
You can do but you have to project it in memory first using Select()
:
var partners = db.PRT_PARTNERS.Select(x=>
new
{
ID =x.ID,
Name = x.First_Name +" "+ x.Last_Name
});
ViewBag.partners = new SelectList(partners , "ID", "Name");
Upvotes: 1