I have a method in which return me selectList. The certain items of selectList are to be programatically removed on the basis of Key.
public SelectList GetRoutingActionList()
{
Dictionary<string, string> routingActions = new Dictionary<string, string> {
{ "Approved", "Approve" },
{ "Return To", "Return To .." },
{ "Return To Sender", "Return To Sender" },
{ "Disapprove", "Disapprove" },
{ "Set On Hold", "Set On Hold" }
};
SelectList routingActionList = new SelectList(routingActions, "Key", "Value");
return routingActionList;
}
For eaxmple , I have to remove the item with Key "Disapprove". Could any one kindly help me to solve this.
You have to use
Where()
to filter them and then pass returned object ofList<SelectListItem>
toSelectList
constructor to get the new SelectList which will not have item with Value "Disapprove" this way: