views:

743

answers:

1

I wish to redirect to a route but also specify the action to run on that route's controller.

I tried this:

Response.RedirectToRoute("Login", new { action = "ChangePassword" });

The action looks like this:

public ActionResult ChangePassword()
{}

The route looks like this:

routes.MapRoute("Login", "Login/{action}", new { controller = "Login", 
action = "Index" } );

The error I get is :

System.NotImplementedException: The method or operation is not implemented.

Can you see what I'm doing wrong?

A: 

Well, you only get NotImplementedException when something throws it. So look at the stack trace (Call Stack) and find the routine which threw it. When VS automatically implements an interface, for example, the body will throw this; you're expected to replace the implementation.

Craig Stuntz
This is the top of the stack: at System.Web.HttpResponseBase.RedirectToRoute(String routeName, Object routeValues) at MVCApp.Controllers.LoginController.TryFormsLogin(String username, String password) in C:\Dev\AspenMVCTemplate\Src\Main\MVCApp\MVCApp\Controllers\LoginController.cs:line 110
Wackyphill
So IE RedirectToRoute is throwing the exception right?
Wackyphill
No, `RedirectToRoute` won't throw this. But the thing which `RedirectToRoute` eventually causes to be *called* (say, a function called by your action) just might. Try looking at a stack on any `InnerException` you might have.
Craig Stuntz
I don't believe the action is ever called because I can manually goto the URL for the action and its fine. I think the problem is w/ my call to RedirectToRoute(). I think it doesn't find the route or something. I just don't understand why. The action itself is working perfect. The RouteRedirect is where I'm confused.
Wackyphill
`RedirectToRoute` does not (directly) throw any exceptions at all. I just looked in the MVC source code to confirm this. Some other function is throwing this exception.
Craig Stuntz