我一直在尝试从MVC Futures项目中获得RedirectToAction的强类型版本,但我一直没有收到任何地方的信息。以下是我所遵循的步骤以及我遇到的错误。任何帮助深表感谢。引起RedirectToAction问题的MVC2和MVC期货
我创建了一个新的MVC2应用程序,并将HomeController上的About操作改为重定向到Index页面。
Return RedirectToAction("Index")
不过,我想使用强类型的扩展名,所以我从CodePlex上下载的MVC期货,并添加到Microsoft.Web.Mvc引用到我的项目。
我addded下面的“导入”语句来HomeContoller.vb
Imports Microsoft.Web.Mvc
顶部我注释掉上述RedirectToAction并添加以下行:
Return RedirectToAction(Of HomeController)(Function(c) c.Index())
到目前为止,一切都很好。然而,我发现,如果我取消了第一个(非通用)RedirectToAction,这是现在导致以下编译错误:
Error 1 Overload resolution failed because no accessible 'RedirectToAction' can be called with these arguments:
Extension method 'Public Function RedirectToAction(Of TController)(action As System.Linq.Expressions.Expression(Of System.Action(Of TController))) As System.Web.Mvc.RedirectToRouteResult' defined in 'Microsoft.Web.Mvc.ControllerExtensions': Data type(s) of the type parameter(s) cannot be >inferred from these arguments. Specifying the data type(s) explicitly might correct this error.
Extension method 'Public Function RedirectToAction(action As System.Linq.Expressions.Expression(Of System.Action(Of HomeController))) As System.Web.Mvc.RedirectToRouteResult' defined in 'Microsoft.Web.Mvc.ControllerExtensions': Value of type 'String' cannot be converted to 'System.Linq.Expressions.Expression(Of System.Action(Of mvc2test1.HomeController))'.
即使智能影音意义是显示8个重载(原6个非通用的过载,加上来自期货组合的两个新的泛型重载),似乎在试图编译代码时,编译器只会从期货评估中'找到'2种非gneneric扩展方法。
我想这可能是我用的版本冲突的MVC2组件的问题,期货组装,所以我从期货加入MvcDiaganotics.aspx下载到我的项目,everytyhing看着正确的:
ASP .NET MVC大会信息(System.Web.Mvc.dll程序)
大会版本:ASP.NET MVC 2 RTM(2.0.50217.0)
全名:System.Web.Mvc,版本= 2.0 .0.0,文化=中立,PublicKeyToken = 31bf3856ad364e35
代码基地:文件:/// C:/WINDOWS/assembly/GAC_MSIL/System.Web.Mvc/2.0.0.0__31bf3856ad364e35/System.Web.Mvc.dll
部署:GAC部署
ASP.NET MVC期货大会信息(Microsoft.Web.Mvc.dll)
大会版本:ASP.NET MVC 2个RTM期货(2.0.50217.0)
全名:Microsoft.Web.Mvc ,Version = 2.0.0.0,Culture = neutral,PublicKeyToken = null
代码库:文件:///xxxx/bin/Microsoft.Web.Mvc.DLL
部署:仓部署
这是推动我疯了!因为我认为这可能是一些VB问题,我使用C#创建了一个新的MVC2项目,并尝试与上面相同。
我添加了下面的“使用”语句来HomeController.cs
using Microsoft.Web.Mvc;
这一次的顶部,在关于操作方法,我只能管理由输入完整调用非通用RedirectToAction条命令如下:
return Microsoft.Web.Mvc.ControllerExtensions.RedirectToAction<HomeController>(this, c => c.Index());
即使我有“使用”的声明在类的顶部,如果我试着拨打非通用RedirectToAction如下:
return RedirectToAction<HomeController>(c => c.Index());
我会得到以下编译错误:
Error 1 The non-generic method 'System.Web.Mvc.Controller.RedirectToAction(string)' cannot be used with type arguments
是怎么回事?这不是我想做的事情不寻常。 这是一个简单的香草MVC2项目,仅提及期货组合。
我希望我已经错过了一些明显的东西,但我一直在挠我的头太久,所以我想我会寻求一些帮助。
如果有人设法让这个简单的场景工作(在VB和/或C#中),请让我知道什么,如果有的话,他们做了什么不同?
谢谢!
这对我的C#项目没有什么窍门。是否有理由需要使用'this'关键字?我认为这是隐含的。 – Darragh 2010-04-13 08:12:33