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
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With