开发者

MVC 2 RC RedirectToAction woes

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/Sea开发者_StackOverflow中文版rch/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


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 });


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜