开发者

How can a formcollection be enumerated in ASP.NET MVC2

I was previously using How can a formcollection be enumerated in ASP.NET MVC? 's implementation but now I'm on VS2010 and MVC2 its complaining:


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

The code is ...

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();
...

Did something change开发者_JAVA技巧 when I wasn't looking; this compiles and works and runs and has no issues in MVC1; but wont compile in 2.

Thanks

Update

I techically just fixed this by using:

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

instead.

But I'd still be interested in why it changed between versions.


I techically just fixed this by using:

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

Linebreak added after collection. for formatting

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜