MVC2 and MVC Futures Causing RedirectToAction Issues

I tried to get the strongly typed version of RedirectToAction from the MVC Futures project to work, but I didn't get anything. Below are the steps I followed and the errors I encountered. Any help is greatly appreciated.

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

Return RedirectToAction("Index")

      

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

I added 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 that if I uncomment the first (non-generic) RedirectToAction, it now throws the following compilation error:

Error 1 Could not resolve overload because no available "RedirectToAction" is available with these arguments:
   Extension Method 'Public Function RedirectToAction (from TController) (action as System.Linq.Expressions.Expression (from System.Action (from TController))) As System.Web.Mvc.RedirectToRouteResult 'is defined in' Microsoft.Web.Mvc.ControllerExtensions': The data type of the type parameter (s) cannot be specified from these arguments. Specifying the data type (s) explicitly can 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 type "String" cannot be converted to "System.Linq.Expressions.Expression (Of System.ction (Of mvc2test1.HomeController))".

Even though intelli-sense was showing 8 overloads (the original 6 non-generic overloads, plus 2 new generic overloads from the Futures assembly), it seems that when trying to execute the code, the compiler will only "find" 2 non-gneneric extension methods from the evaluation of the future futures.

I thought it might be a problem when I use conflicting versions of MVC2 build and futures build, so I added MvcDiaganotics.aspx from the Futures download to my project and everything looked correct:

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

Build version : ASP.NET MVC 2 final release (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.03130b3538ad364e35 / System.Web.Mvc.dll
Deployment : Deployed GAC

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

Assembly Version : ASP.NET MVC 2 RTM Platform 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

It drives me crazy! Becuase I thought it might be a VB problem, I created a new MVC2 project using C # and tried the same as above.

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

using Microsoft.Web.Mvc;

      

This time, in the About action method, I only managed to call the non-generic RedirectToAction by typing the full command like this:

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 a non-generic RedirectToAction like this:

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

      

I would get the following compilation error:

Error 1 Non generic method "System.Web.Mvc.Controller.RedirectToAction (string)" cannot be used with type arguments

What gives? It doesn't look like I'm trying to do something out of the ordinary. This is a simple vanilla MVC2 project with reference only to the Futures build.

I hope I missed something obvious, but I've been scratching my head for too long so I figured I would look for some help.

If anyone managed to execute this simple script (in VB and / or C #), could they tell me that, if anything, they did differently?

Thank!

+2


source to share


1 answer


Try using:

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

      



Using a qualifier this

allows extension methods to be used.

+3


source







All Articles