0

I have done a single list DropDownList in MVC 4 Using razor

<td>@Html.DropDownListFor(m => m.COAId, (SelectList)ViewBag.clientsList, "Please Select Client")</td>

I am getting items from database, now i want to add second column of CITY with tha name of client, how can i make it multicolumn?

Mudassar Shaheen
  • 1,397
  • 1
  • 9
  • 15
  • Possible duplicate of [MVC SelectList combining multiple columns in text field](http://stackoverflow.com/questions/12727285/mvc-selectlist-combining-multiple-columns-in-text-field) – Divyang Desai Dec 16 '16 at 12:27

1 Answers1

1

Controller

var clients = db.ClientsTbls
        .Select(s => new
            {
            Text = s.Name + "-" + s.City,
            Value = s.clientId
        })
        .ToList();

ViewBag.clientsList= new SelectList(clients, "Value", "Text");

View

<td>@Html.DropDownListFor(m => m.COAId, (SelectList)ViewBag.clientsList, "Please Select Client")</td>
jignesh
  • 1,639
  • 1
  • 16
  • 18