返回数据库表中的项列表

cra*_*mar 0 c# asp.net-mvc-5

我不确定我做错了什么.我想返回要在下拉框中使用的值/项对的列表.我收到以下错误.

Cannot implicitly convert type 
System.Collections.Generic.List<System.Web.Mvc.SelectListItem> to
System.Collections.Generic.List<string>
Run Code Online (Sandbox Code Playgroud)

导致错误的方法如下.

方法

    //Get the shift list based on StationId which is foreign key in Shifts table.
    public List<string> GetShiftsByStationId(int stationId)
    {
        //Created DataContext to query DB.
        using (DataManager db = new DataManager())
        {
            //returns all the records from table based on StationId in list format.
            return db.Shifts.Where(query => query.StationId == stationId).Select(q => new SelectListItem { Value = q.ShiftId.ToString(), Text = q.Code }).ToList();
        }
    }
Run Code Online (Sandbox Code Playgroud)

ram*_*ilu 5

public List<string> GetShiftsByStationId(int stationId)
Run Code Online (Sandbox Code Playgroud)

应该如下所示(因为在您选择的LINQ查询中new SelectListItem)

public List<SelectListItem> GetShiftsByStationId(int stationId)
Run Code Online (Sandbox Code Playgroud)