开发者

asp.net mvc dictionary sort

开发者 https://www.devze.com 2023-01-23 21:24 出处:网络
return new M开发者_StackOverflowultiSelectList(dic, \"Key\", \"Value\", sel); How can I sort by value in the dictionary value above? The dictionary is filled by database values.You could sort the \"
return new M开发者_StackOverflowultiSelectList(dic, "Key", "Value", sel);

How can I sort by value in the dictionary value above? The dictionary is filled by database values.


You could sort the "database values" before adding them to the dictionary, but that would not be entirely reliable.

Use LINQ - type

return 
    new MultiSelectList
    (
       dic.OrderBy(x => x.Value), 
       "Key", 
       "Value", 
        sel
    )
;
0

精彩评论

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