How to filter SelectList with linq

Viewed 8570

I tried to filter the SelectList with where clause but i get the following error.

Unable to cast object of type 'WhereEnumerableIterator`1[System.Web.Mvc.SelectListItem]' to type 'System.Web.Mvc.SelectList'.

public SelectList ReadDocumentHeaderTypeList()
{
    using (context = new Pinc_DBEntities())
    {
        List<SelectListItem> seList =
            (from tb in context.tblDocumentHeaderTypes
            select new SelectListItem
            {
                Value = SqlFunctions.StringConvert((double)tb.DocumentHeaderTypeID).Trim(),
                Text = tb.DocumentHeaderTypeDescription,
            }).OrderBy(o => o.Text).ToList();
        SelectList slist = new SelectList(seList, "Value", "Text");
        return slist;
    }
}

SelectList sl = (SelectList)rep.ReadDocumentHeaderTypeList().Where(o => o.Value == "5" && o.Value == "6");//Error occurs here  
2 Answers
Related