Reputation: 4387
I've just updated to VS2010 (rc) and subsequently been forced to update my projects and convert to MVC2 (ta microsoft)... which has scuppered the first app its touched.
Error 2 'System.Web.Mvc.IValueProvider' does not contain a definition for
'Where' and no extension method 'Where' accepting a first argument of type
'System.Web.Mvc.IValueProvider' could be found (are you missing a using directive or an
assembly reference?) ~\Controllers\DiscountsController.cs 51 39 ODSe
Considering I know this works in VS2008 - MVC1 I'm a tad thrown. Anyone?
I currently have (included)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Mvc.Ajax;
using ODSe.Models;
using System.Text;
using System.Text.RegularExpressions;
using System.Net.Mail;
Shouldnt need to be .net 4 as the original project was 3.5; and MVC2 is .net 3.5 (ASP.NET MVC 2 RC 2 provides a new Model-View-Controller (MVC) framework on top of the existing ASP.NET 3.5 SP1 runtime.)
Code Around 51
foreach (var x in this.ValueProvider.Where(k => k.Key.StartsWith("discount.")))
{
if (String.IsNullOrEmpty(x.Value.AttemptedValue))
{
ModelState.SetModelValue(x.Key, new ValueProviderResult(ValueProvider[x.Key].AttemptedValue, collection[x.Key], System.Globalization.CultureInfo.CurrentCulture));
Discount = true;
}
}
When the code was written for MVC(1) in VS2008 this.ValueProvider was "IDictionary ControllerBase.ValueProvider. In MVC(2) VS2010 it throws a hissy fit about using where though this is apparently fine.
foreach (var x in this.ValueProvider)
{
if (x.Key.StartsWith("discount."))
{
if (String.IsNullOrEmpty(x.Value.AttemptedValue))
{
ModelState.SetModelValue(x.Key, new ValueProviderResult(ValueProvider[x.Key].AttemptedValue, collection[x.Key], System.Globalization.CultureInfo.CurrentCulture));
Discount = true;
}
}
}
If not a butt ugly piece of code; Legacy Code is soooo much fun
Upvotes: 2
Views: 1251
Reputation: 84744
IValueProvider
does not extend IEnumerable<T>
, so LINQ extension methods like Where
won't be available.
IValueProvider
is new in MVC 2, so it's possible that you are accessing a property that was IEnumerable<T>
in MVC 1.
Can you provide the code at NewDiscountsController.cs 51
?
Upvotes: 4