帮助将asp.net mvc 1迁移到mvc 2

时间:2022-11-12 00:16:25

I just joined a team thats developing a asp.net mvc 1 application. I only have visual studio 2010 installed which comes with mvc 2.

我刚刚加入了一个开发asp.net mvc 1应用程序的团队。我只安装了带有mvc 2的visual studio 2010。

I ran the conversion wizard and now the app doesnt seem to compile

我运行了转换向导,现在应用程序似乎没有编译

The error I get is

我得到的误差是

"Cannot apply indexing with [] to an expression of type 'System.Web.Mvc.IValueProvider"

"无法将[]索引应用于'System.Web.Mvc.IValueProvider '类型的表达式"

i get this error 5 times in different places of the app.

我在应用的不同地方得到5次错误。

The line is

这条线是

ModelState.SetModelValue(inputTagName, new ValueProviderResult(ValueProvider[inputTagName].AttemptedValue, file.FileName, System.Globalization.CultureInfo.CurrentCulture));

To be honest I've no clue on what its doing but my peers (using Mvc 1) dont have trouble compiling.

老实说,我不知道它在做什么,但是我的同行(使用Mvc 1)在编译时没有问题。

Please help.

请帮助。

2 个解决方案

#1


2  

This is one of the (few) breaking changes between MVC 1 and MVC 2. The ValueProvider has been completely redone to support multiple value providers and no longer has an index property. The short answer is to change this to use GetValue( inputTagName ). The longer (and better) answer is to change the code to use models for your action method inputs and not pull the data out of the value provider directly in your code. Rather, you rely on model binding to access the value provider and set the properties on your model.

这是MVC 1和MVC 2之间的(很少)打破的变化之一。ValueProvider已经被完全重做以支持多个值提供程序,并且不再具有索引属性。简短的答案是将其更改为使用GetValue(inputTagName)。更长的(更好的)答案是修改代码,为操作方法输入使用模型,而不是在代码中直接从值提供程序中提取数据。相反,您需要依赖模型绑定来访问值提供程序并在模型上设置属性。

#2


0  

Change ValueProvider[inputTagName].AttemptedValue to ValueProvider.GetValue(inputTagName).AttemptedValue.

改变ValueProvider[inputTagName]。.AttemptedValue AttemptedValue ValueProvider.GetValue(inputTagName)。

Note that your entire team should be developing against the same version of ASP.Net MVC; otherwise; you'll run into lots of trouble.

注意,您的整个团队应该针对相同版本的ASP进行开发。净MVC;否则;你会遇到很多麻烦的。

#1


2  

This is one of the (few) breaking changes between MVC 1 and MVC 2. The ValueProvider has been completely redone to support multiple value providers and no longer has an index property. The short answer is to change this to use GetValue( inputTagName ). The longer (and better) answer is to change the code to use models for your action method inputs and not pull the data out of the value provider directly in your code. Rather, you rely on model binding to access the value provider and set the properties on your model.

这是MVC 1和MVC 2之间的(很少)打破的变化之一。ValueProvider已经被完全重做以支持多个值提供程序,并且不再具有索引属性。简短的答案是将其更改为使用GetValue(inputTagName)。更长的(更好的)答案是修改代码,为操作方法输入使用模型,而不是在代码中直接从值提供程序中提取数据。相反,您需要依赖模型绑定来访问值提供程序并在模型上设置属性。

#2


0  

Change ValueProvider[inputTagName].AttemptedValue to ValueProvider.GetValue(inputTagName).AttemptedValue.

改变ValueProvider[inputTagName]。.AttemptedValue AttemptedValue ValueProvider.GetValue(inputTagName)。

Note that your entire team should be developing against the same version of ASP.Net MVC; otherwise; you'll run into lots of trouble.

注意,您的整个团队应该针对相同版本的ASP进行开发。净MVC;否则;你会遇到很多麻烦的。