Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/306.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在DropDownListFor中显示多个值_C#_Asp.net Mvc_Html_Razor - Fatal编程技术网

C# 在DropDownListFor中显示多个值

C# 在DropDownListFor中显示多个值,c#,asp.net-mvc,html,razor,C#,Asp.net Mvc,Html,Razor,您好,我如何在DropDonwListFor中显示名称和姓氏,因为在我的示例中,我显示的名称没有姓氏 @Html.DropDownListFor(@model => @model.Conseiller, new SelectList(ViewBag.User, "Id","Name", "LastName"), new { @class = "form-controml"}) 您可以组合两列,然后使用全名变量作为SelectListdisplay string FullName = st

您好,我如何在DropDonwListFor中显示名称和姓氏,因为在我的示例中,我显示的名称没有姓氏

@Html.DropDownListFor(@model => @model.Conseiller, new SelectList(ViewBag.User, "Id","Name", "LastName"), new { @class = "form-controml"})

您可以组合两列,然后使用全名变量作为
SelectList
display

string FullName = string.Format("{0} {1}", User.Name, User.LastName);

您可以组合两列,然后使用全名变量作为
SelectList
display

string FullName = string.Format("{0} {1}", User.Name, User.LastName);

您需要在控制器中构建和
IEnumerable
(其中,
Text
属性的值是
Name
LastName
的串联值,您必须在查询时将Name和LastName组合起来,并将其与viewmodel一起传递给您需要在控制器中构建的视图和
IEnumerable
)(如果
Text
属性的值是
Name
LastName
的串联值,则在查询时必须组合Name和LastName,并将其与viewmodel一起传递给viewmodel,不要使用
+
进行字符串串联。使用
string.Format(“{0}{1}”,User.Name,User.LastName)
更有效。字符串是不可变的,因此每次执行
+
时都会创建一个新实例。请看这里:不要使用
+
进行字符串连接。使用
string.Format(“{0}{1}”,User.Name,User.LastName)
更有效。字符串是不可变的,因此每次执行
+
操作时,您都会创建一个新实例。请看这里: