I am following the blog to use ASP.Net MVC MultiSelectList in my app. I am running into

"System.ArgumentException: At least one object must implement IComparable." error.

I am using ASP.Net MVC 5.2.3. My controller has an action populates a MultiSelectList and assigns it to a ViewBag.stations variable like this:

var qryResult = DB.getPatientInfoCompleted(StationIDs);            
var theseStations = qryResult.Select(x => new
{
    StationID = x.StationID,
    StationName = x.StationName
}).Distinct().OrderBy(x => x);
ViewBag.station = new MultiSelectList(theseStations, "StationID", "StationName");

The razor view has

<td>
    @Html.DropDownList("station2", (MultiSelectList)ViewBag.stations, new { multiple = "multiple"})
</td>

<td>
    @Html.ListBox("station", (MultiSelectList)ViewBag.stations, new { @id = "lstMultiSelect", @class = "btn btn-default btn-sm dropdown-toggle menu-width" })
</td>

Thanks for your help.

Related posts

Recent Viewed