現在、IDを書き込み、フォームにFirstNameを表示するSelectListがあります。
ViewBag.Person = new SelectList(db.Person, "ID", "FirstName");
FirstNameとLastNameをSelectListに連結する方法は?何かのようなもの:
ViewBag.Person = new SelectList(db.Person, "ID", "FirstName & LastName");
現在、IDを書き込み、フォームにFirstNameを表示するSelectListがあります。
ViewBag.Person = new SelectList(db.Person, "ID", "FirstName");
FirstNameとLastNameをSelectListに連結する方法は?何かのようなもの:
ViewBag.Person = new SelectList(db.Person, "ID", "FirstName & LastName");
次のようなものを試してください。
ViewBag.Person =
new SelectList((from s in db.Person select new {
ID=s.ID,
FullName = s.FirstName+ " " + s.LastName}),
"ID",
"FullName",
null);
または、Personモデルに新しいプロパティを追加します
public string Fullname
{
get
{
return string.Format("{0} {1}", FirstName, LastName);
}
}