views:

300

answers:

2

Hiya!

I have setup a custom route as defined in my global.asax:

routes.MapRoute(
        "Search", "{controller}/{action}/{type}/{searchterm}",
        new { controller = "Search", action = "Results", type = "", searchterm = "" } 
        );

Now all I want to do it in a controller when data is passed via POST basically go in the format:

http://localhost/Search/Results/2/RG12%201JD

Instead what happens is:

http://localhost/Search/Results?type=1&searchterm=RG12%201JD

What am I doing wrong, the offending code is:

return RedirectToAction("Results",new {type = "1", searchterm = "RG12%201JD" });

Any help would be greatly appreciated!

Thanks

Jonathan

+2  A: 

Clanger!!! I found it I needed to use RedirectToRoute!!!! Doing this solves the issue!

return RedirectToRoute("Search", new { controller = "Search", action = "Results", searchterm = strsearchterm, type = inttype });
JonathanTien
A: 

I've noticed the same behavior in MVC 2 RTM (we weren't having these problems in MVC 1). Would appreciate a pointer to the details in how routing is handled between the two methods. I was trying to pass in a RouteValueDictionary to RedirectToAction to accomplish the same thing but it was never populating more than controller and action keys in the dictionary for the target action method.

Jason Kossowan