Skip to content
Loading
How to filter a public IEnumerable<SelectListItem> with .Where?  
  • class="col-8">  
  • for="Proposal.ProposalReference" class="form-control" />  
  • for="Proposal.ProposalReference" class="text-danger">  
  •   
  •   
  • class="form-group row">  
  • class="col-4">  
  • Category  
  •   
  • class="col-8">  
  • @Html.DropDownListFor(m => m.Proposal.ProposalCategoryId, Model.ProposalCategoryList, "--Select a Category--",  
  • new { @class = "form-control" })  
  • for="Proposal.ProposalCategoryId" class="text-danger">  
  •   
  •   
  • class="form-group row">  
  • class="col-4">  
  • for="Proposal.ProposalDate">  
  •   
  • class="col-8">  
  • for="Proposal.ProposalDate" class="form-control date-input" />  
  • for="Proposal.ProposalDate" class="text-danger">  
  •   
  •   
  • class="form-group row">  
  • class="col-8 offset-4">  
  • @if (Model.Proposal.ProposalId != 0)  
  • {  
  • "_EditAndBackToListButton" model="Model.Proposal.ProposalId" />  
  • }  
  • else  
  • {  
  • "_CreateAndBackToListButton" />  
  • }  
  •   
  •   
  •   
  •   
  • }  
  • }  
  • return View(proposalVM);  
  • }  
  • Nikunj Satasiya
    Hi Nicholas, Please try this solution.
     
    But Before Implement, this solution checks the following points first.
     
    1) _unitOfWork.ProposalCategory.GetAll() return value or returnig null value?
    2) proposalVM.ProposalCategoryList is IEnumerable ?
     
    Solution
    1. proposalVM.ProposalCategoryList =   
    2. (from txt in _unitOfWork.ProposalCategory.GetAll().Where(s => s.ProposalCategoryName != "Freight").OrderBy(s => s.ProposalCategoryName).AsEnumerable()  
    3.     select new SelectListItem()  
    4.     {  
    5.         Text = txt.Description,  
    6.         Value = txt.Id.ToString()  
    7. });  
     Thank you.