简体   繁体   English

MVC到MVC2错误

[英]MVC to MVC2 Errors

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. 我刚刚更新到VS2010(rc),随后被迫更新我的项目并转换为MVC2(微软)...这破坏了它所涉及的第一个应用程序。

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. 考虑到我知道这在VS2008中有效-MVC1我有点不满意。 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; 不应为.net 4,因为原始项目为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.) MVC2是.net 3.5(ASP.NET MVC 2 RC 2在现有ASP.NET 3.5 SP1运行时的基础上提供了一个新的模型视图控制器(MVC)框架。)

Code Around 51 约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. 当在VS2008中为MVC(1)编写代码时,this.ValueProvider是“ 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;
                            }
                        }
                    }

If not a butt ugly piece of code; 如果不是一段糟糕的代码; Legacy Code is soooo much fun 旧版代码非常有趣

IValueProvider does not extend IEnumerable<T> , so LINQ extension methods like Where won't be available. IValueProvider不会扩展IEnumerable<T> ,因此LINQ扩展方法(如Where将不可用。

IValueProvider is new in MVC 2, so it's possible that you are accessing a property that was IEnumerable<T> in MVC 1. IValueProvider是MVC 2中的新增功能,因此可能会访问MVC 1中的IEnumerable<T>属性。

Can you provide the code at NewDiscountsController.cs 51 ? 您可以在NewDiscountsController.cs 51提供代码吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM