开发者

asp.net mvc dictionary sort

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜