2012-08-17 58 views
2

我有一本字典,我想在我的视图页面上显示一个列表。目前我可以创建一个列表,但我不能设置动态大小或填充我的字典。我想做一些像foreach一样的事情,或者如果有更快的列表功能?创建一个列表来显示字典的内容?

即时通讯新的MVC对不起,代码糟糕。

@model Dictionary<string, string> 
@{ 
    ViewBag.Title = "Download"; 
} 
<hgroup class="title"> 
    <h1>@ViewBag.Title.</h1> 
    <h2>@ViewBag.Message</h2> 
    <br> 
    @{ 
     var filelist = @Model.ToList(); 
    }  
    <Div> 
    <select name="Fileslist" size="5"> 
     <option>Count</option> 
     <option>text2</option> 
     <option>text3</option> 
     <option>text4</option> 
     <option>text5</option> 
    </select> 
    </Div> 
</hgroup> 

回答

2

简单的字典到列表将

Dictionary<string, string> myDictionary = new Dictionary<string, string>(); 

// Add some values in dictionary 

var res = myDictionary.Select(x => x.Key + "-" + x.Value).ToList() 
相关问题