0

hello how can i show a Name and LastName in DropDonwListFor, Because in my example i show Name without LastName

@Html.DropDownListFor(@model => @model.Conseiller, new SelectList(ViewBag.User, "Id","Name", "LastName"), new { @class = "form-controml"})
AddRock
  • 71
  • 2
  • 8
  • 4
    You need to build and `IEnumerable` in your controller (where the value of the `Text` property is the concatenated values of `Name` and `LastName` –  Jan 25 '17 at 10:48
  • You have to combine Name and Lastname at the time of query and pass it with a viewmodel to view – Hemal Jan 25 '17 at 10:51

1 Answers1

2

You can combine two columns and then use FullName variable as SelectList display

string FullName = string.Format("{0} {1}", User.Name, User.LastName);
kgzdev
  • 2,770
  • 2
  • 18
  • 35
  • Don't use `+` for string concatenation. Using `string.Format("{0} {1}", User.Name, User.LastName)` is more efficent – Alex Art. Jan 25 '17 at 10:53
  • Performance. strings are immutable so each time you do `+` you create a new instance. Take a look here: http://stackoverflow.com/questions/10341188/string-concatenation-using-operator – Alex Art. Jan 25 '17 at 11:00