Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 720
Chris McKee Avatar asked Jun 16 '10 10:06

Chris McKee


1 Answers

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

like image 182
Chris McKee Avatar answered Oct 21 '22 06:10

Chris McKee