Reputation: 177
In my ViewBag there is object that contains Id,First name and Last name. I want to display DropDownList that has Id as value and "First name"+" "+"Last Name" as text.
@Html.DropDownListFor(model => model.Id, new SelectList(ViewBag.person, "Id","Last Name"), new { @class = "form-control" })
This is the line of code that I use currently, how can I modify it to display the right info?
Upvotes: 0
Views: 423
Reputation: 59336
You have to modify your controller and model to send the concatenated text to the View, or create a new SelectList
in the View itself that concatenates the values before passing it to the DropdownListFor
.
What you are trying to achieve would be possible if SelectList
had an overload with a callback for formatting, but this isn't possible.
Upvotes: 1