如何将RedirectToAction转到主页?

时间:2010-08-10 08:24:02

标签: asp.net-mvc

如何将页面重定向到主页?

if (p == -1)
                return RedirectToAction("Index");

这会在网址中打开http://abc.com/Index之类的网页 我想要http://abc.com

2 个答案:

答案 0 :(得分:8)

脱离我的头顶

return Redirect("~");

答案 1 :(得分:3)

您应该在Global.asax.cs文件中使用默认值进行正确的路由。 例如

routes.MapRoute(
                "Default",                                              // Route name
                "{controller}/{action}/{id}",                           // URL with parameters
                new { controller = "Home", action = "Index", id = "" }  // Parameter defaults
            );

之后

if (p == -1)
                return RedirectToAction("Index", "Home");