我刚刚更新到VS2010 (rc),随后被迫更新我的项目,并转换为MVC2 (ta微软).这破坏了第一款触碰到的应用程序。
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考虑到我知道这在VS2008 - MVC1中是可行的,我简直是一塌糊涂。有没有人?
我目前有(包括)
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;不应该是.net 4,因为最初的项目是3.5;MVC2 is .net 3.5 (ASP.NET MVC 2 RC2在现有的ASP.NET 3.5 SP1运行时之上提供了一个新的模型-视图-控制器(MVC)框架)。
码约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;
}
}在VS2008 this.ValueProvider中为MVC(1)编写的代码是"IDictionary ControllerBase.ValueProvider“,而在MVC(2) VS2010中,它很适合在显然很好的地方使用。
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;
}
}
}如果不是一个令人讨厌的代码;遗产代码是非常有趣的
发布于 2010-03-01 12:14:24
IValueProvider不扩展IEnumerable<T>,所以像Where这样的LINQ扩展方法将不可用。
IValueProvider在MVC 2中是新的,所以您可能正在访问MVC 1中的IEnumerable<T>属性。
你能在NewDiscountsController.cs 51提供代码吗?
https://stackoverflow.com/questions/2355326
复制相似问题