asp.net-mvc-2 – 如何在ASP.NET MVC2中枚举formcollection

我之前使用的是 How can a formcollection be enumerated in ASP.NET MVC?的实现,但现在我在VS2010和MVC2上抱怨:

Error   1   Cannot implicitly convert type 'System.Web.Mvc.IValueProvider' to 
'System.Collections.Generic.IDictionary'. An 
explicit conversion exists (are you missing a cast?)    C:\~\ProjectMVC\Controllers\TheController.cs    line    ProjectMVC

代码是……

IDictionary<string,ValueProviderResult> tmpCollection = collection.TovalueProvider();

for (int j = 1; j <= noprops; j++)
            {
                string shopNmTmp =
                    (from t in tmpCollection
                     where t.Key.StartsWith(j + ".discount.sname." + j)
                     select t.Value.AttemptedValue).First();
                string shopCdTmp =
                    (from t in tmpCollection
                     where t.Key.StartsWith(j + ".discount.sref." + j)
                     select t.Value.AttemptedValue).First();
...

当我不看时,有什么改变;这编译,工作和运行,在MVC1中没有问题;但不会在2中编译.

谢谢

更新

我通过使用以下技术来解决这个问题:

Dictionary<string,string> tmpCollection = collection.AllKeys.ToDictionary(k => k,v => collection[v]);

代替.

但是我仍然对它为什么在版本之间发生变化感兴趣.

解决方法

我通过使用以下技术来解决这个问题:
Dictionary<string,string> tmpCollection = collection.
                                 AllKeys.ToDictionary(k => k,v => collection[v]);

收集后添加了Linebreak.用于格式化

相关文章

### 创建一个gRPC服务项目(grpc服务端)和一个 webapi项目(...
一、SiganlR 使用的协议类型 1.websocket即时通讯协议 2.Ser...
.Net 6 WebApi 项目 在Linux系统上 打包成Docker镜像,发布为...
一、 PD简介PowerDesigner 是一个集所有现代建模技术于一身的...
一、存储过程 存储过程就像数据库中运行的方法(函数) 优点:...
一、Ueditor的下载 1、百度编辑器下载地址:http://ueditor....