你好,我怎麼能顯示DropDonwListFor一個名字和姓氏,因爲在我的例子我展示名稱沒有名字在DropDownListFor顯示很多值
@Html.DropDownListFor(@model => @model.Conseiller, new SelectList(ViewBag.User, "Id","Name", "LastName"), new { @class = "form-controml"})
你好,我怎麼能顯示DropDonwListFor一個名字和姓氏,因爲在我的例子我展示名稱沒有名字在DropDownListFor顯示很多值
@Html.DropDownListFor(@model => @model.Conseiller, new SelectList(ViewBag.User, "Id","Name", "LastName"), new { @class = "form-controml"})
您可以合併兩列,然後使用全名變量SelectList
顯示
string FullName = string.Format("{0} {1}", User.Name, User.LastName);
的視圖模型不要使用'+'作爲字符串連接。使用'string.Format(「{0} {1}」,User.Name,User.LastName)'更有效 –
感謝,有效閱讀代碼或性能? –
表現。字符串是不可變的,所以每次你用'+'創建一個新的實例。看看這裏:http://stackoverflow.com/questions/10341188/string-concatenation-using-operator –
你需要在你的控制器建立和'的IEnumerable'(其中'Text'屬性的值是Name'的'連接值和'LastName' –
你必須名稱和姓氏的結合查詢的時間並傳遞給它查看 – Hemal