开发者

Filtering SelectListItem using a string array.-mvc

I have tow variables in my mvc application .that is shown below

   public IEnumerable<SelectListItem> AvailableAgents { get; set; }
   public string[] AvailableAgentSelect开发者_如何学运维ed { get; set; }
   public IEnumerable<SelectListItem> AgentsNotselected{ get; set; }

The AvailableAgents contains all agent list items. and AvailableAgentSelected is a string array it contains values of selected agents only..

From the above data how can i store the agents who are not selected to AgentsNotselected (means,select all agent list items whose values are not in AvailableAgentSelected ) . I want an efficeiant way to do it .


Your last property has two types, I asume it's IEnumerable. I didn't try it, but this should work, although the "efficient" part is questionable.

AgentsNotselected = AvaliableAgents.Where(a => !AvailableAgentSelected.Contains(a.Value));
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜