我返回一些存储的联系人以查看DropDownList,并且我无法在我的SelectList上包含多个dataTextFields.
目前我有:
@Html.DropDownListFor(model => model.Account.AccountContacts,new SelectList(ViewBag.DDContacts,"Contact.ContactID","Contact.FirstName"),new { @class = "select",style = "width: 100px;" })
我想拥有:
@Html.DropDownListFor(model => model.Account.AccountContacts,"Contact.FullName"),style = "width: 100px;" })
它结合了FirstName和LastName属性.请帮助,谢谢先进!
更新:我知道扩展联系人的属性,我很好奇有一个流线型的方式来完成这一点在视图或控制器.我试过这个解决方案here没有效果. How can I combine two fields in a SelectList text description?
解决方法
延长联系人
public partial class Contact { private string _nameFull; public string NameFull { get{return FirstName + " " + LastName;} } }