MVC2 and MVC Futures causing RedirectToAction issues

Posted by Darragh on Stack Overflow See other posts from Stack Overflow or by Darragh
Published on 2010-04-12T10:37:16Z Indexed on 2010/05/01 19:27 UTC
Read the original article Hit count: 1251

I've been trying to get the strongly typed version of RedirectToAction from the MVC Futures project to work, but I've been getting no where. Below are the steps I've followed, and the errors I've encountered. Any help is much appreciated.

I created a new MVC2 app and changed the About action on the HomeController to redirect to the Index page.

Return RedirectToAction("Index")

However, I wanted to use the strongly typed extensions, so I downloaded the MVC Futures from CodePlex and added a reference to Microsoft.Web.Mvc to my project.

I addded the following "import" statement to the top of HomeContoller.vb

Imports Microsoft.Web.Mvc

I commented out the above RedirectToAction and added the following line:

Return RedirectToAction(Of HomeController)(Function(c) c.Index())

So far, so good. However, I noticed if I uncomment out the first (non Generic) RedirectToAction, it was now causing the following compile error:

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))'.

Even though intelli-sense was showing 8 overloads (the original 6 non-generic overloads, plus the 2 new generic overloads from the Futures assembly), it seems when trying to complie the code, the compiler would only 'find' the 2 non-gneneric extension methods from the Futures assessmbly.

I thought this might be an issue that I was using conflicting versions of the MVC2 assembly, and the futures assembly, so I added MvcDiaganotics.aspx from the Futures download to my project and everytyhing looked correct:

ASP.NET MVC Assembly Information (System.Web.Mvc.dll)

Assembly version: ASP.NET MVC 2 RTM (2.0.50217.0)
Full name: System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
Code base: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Web.Mvc/2.0.0.0__31bf3856ad364e35/System.Web.Mvc.dll
Deployment: GAC-deployed

ASP.NET MVC Futures Assembly Information (Microsoft.Web.Mvc.dll)

Assembly version: ASP.NET MVC 2 RTM Futures (2.0.50217.0)
Full name: Microsoft.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null
Code base: file:///xxxx/bin/Microsoft.Web.Mvc.DLL
Deployment: bin-deployed

This is driving me crazy! Becuase I thought this might be some VB issue, I created a new MVC2 project using C# and tried the same as above.

I added the following "using" statement to the top of HomeController.cs

using Microsoft.Web.Mvc;

This time, in the About action method, I could only manage to call the non-generic RedirectToAction by typing the full commmand as follows:

return Microsoft.Web.Mvc.ControllerExtensions.RedirectToAction<HomeController>(this, c => c.Index());

Even though I had a "using" statement at the top of the class, if I tried to call the non-generic RedirectToAction as follows:

return RedirectToAction<HomeController>(c => c.Index());

I would get the following compile error:

Error 1 The non-generic method 'System.Web.Mvc.Controller.RedirectToAction(string)' cannot be used with type arguments

What gives? It's not like I'm trying to do anything out of the ordinary. It's a simple vanilla MVC2 project with only a reference to the Futures assembly.

I'm hoping that I've missed out something obvious, but I've been scratching my head for too long, so I figured I'd seek some assisstance.

If anyone's managed to get this simple scenario working (in VB and/or C#) could they please let me know what, if anything, they did differently?

Thanks!

© Stack Overflow or respective owner

Related posts about ASP.NET

Related posts about asp.net-mvc