asp.net-mvc – 如何组合两个dataTextFields的SelectList描述在asp.net MVC 3使用@ Html.DropDownListFor

我返回一些存储的联系人以查看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;}
   }
}

相关文章

判断URL文件是不是在于在。private static bool UrlIsExist(...
由于在.net中,Request时出现有HTML或Javascript等字符串时,...
public static bool ProcessIdCard(this string idCard, out...
protected void Page_Load(object sender, EventArgs e){ Sc...