开发者

Combine three values into one in a MVC dropdownlist?

I'm trying to combine the values Fir开发者_StackOverflow社区stName + LastName + Email into a single value for my dropdownlist in a MVC application using linq2sql.

The code I'm using now, that works for only one output value in the list, is:

<%= Html.DropDownList("SaleEmployeeId", new SelectList(ViewData["SaleEmployees"] as IEnumerable, "Id", "FirstName", Model.SaleEmployeeId), "-- Choose --", new { @class = "required" })%>

But I want to combine "FirstName + LastName + Email" where "FirstName" has its place in my dropdownlist.

Does anyone have a solution for this?


You could try this (in your controller):

var values = _userRepository.FindAllUsers().Select(u => new { ID = u.UserName, Name = u.FirstName + " " + u.LastName + " " + u.EmailAddress});
var userDropDown = new SelectList(values, "Id", "Name");

Then put userDropDown in the viewbag/viewdata, and read it in your view.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜