Currently I have SelectList that writes ID, and shows FirstName on the form.
ViewBag.Person = new SelectList(db.Person, "ID", "FirstName");
How to concatenate FirstName and LastName into SelectList? Something like:
ViewBag.Person = new SelectList(db.Person, "ID", "FirstName & LastName");
Try something like this:
ViewBag.Person =
new SelectList((from s in db.Person select new {
ID=s.ID,
FullName = s.FirstName+ " " + s.LastName}),
"ID",
"FullName",
null);
Or Add a new property to your Person model
public string Fullname
{
get
{
return string.Format("{0} {1}", FirstName, LastName);
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With