0

我有以下下拉列表:

@Html.DropDownListFor(c => c.TargetedUser.ManagerUserID, 
    new SelectList(Model.UserList, "UserID", "Username",
    Model.TargetedUser.ManagerUserID), 
    new { @name = "TargetedUser.ManagerUserID" })

在该Username字段中,我真的很想声明用户全名,但这包含在两个字段ForenameSurname. 我尝试了以下方法:

@Html.DropDownListFor(c => c.TargetedUser.ManagerUserID, 
    new SelectList(Model.UserList, "UserID", "Forename" + "Surname", 
    Model.TargetedUser.ManagerUserID), 
    new { @name = "TargetedUser.ManagerUserID" })

但这产生了一个错误,因为它正在寻找一个名为ForenameSurname

4

1 回答 1

1

如何从模型中投影您的列表以具有全名:

@Html.DropDownListFor(c => c.TargetedUser.ManagerUserID, 
                      new SelectList(Model.UserList.Select(x => new { x.UserID, FullName = x.Forename + x.Surname }), "UserID", "FullName",
                                     Model.TargetedUser.ManagerUserID), 
                      new { @name = "TargetedUser.ManagerUserID" })
于 2013-09-25T14:16:56.027 回答