2010-06-22 35 views
0

我正在使用ASP.NET MVC2,并且我想根据HtmlHelper扩展中的地址栏中的当前地址组成一个url。到目前为止,我有这样的:关于字典问题的汇总问题

url = helper.ViewContext.RequestContext.RouteData.Values 
     .Aggregate<KeyValuePair<String, Object>>((w, next) => w + next); 

但是,这不会编译。任何人都有关于如何解决这个聚合函数的好主意?

回答

2

使用此:

helper.ViewContext.RequestContext.RouteData.Values 
       .Select(x => x.Value.ToString()) 
       .Aggregate((c, next) => c + next); 

但既然你想要的东西就像一个网址,我建议你使用这个:

helper.ViewContext.RequestContext.RouteData.Values 
       .Select(x => x.Value.ToString()) 
       .Aggregate((c, next) => c + "/" + next); 

GRZ,克里斯。