How can a formcollection be enumerated in ASP.NET MVC2
Asked Answered
T

1

8

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 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.

Tufted answered 16/6, 2010 at 10:35 Comment(0)
T
14

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

Tufted answered 16/6, 2010 at 10:46 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.