2013-05-08 28 views
0

我們有一個mvc4所在部位HomeController.Index()具有下面的代碼爲什麼RedirectToAction重定向到<param> .COM

RedirectionToAction("Page", new { id = "Home" }); 

其中action頁面被定義爲

public ActionResult Page(string id) 
    ..... 

上調試,它開始爲localhost:xxxxx,但隨後重定向到www.home.com

設置斷點時,它甚至沒有碰到方法Page(string id)

任何線索在哪裏看?

+0

做一個解決方案廣泛的搜索'home.com'你可能有它定義的地方,它導致重定向(也許你的默認錯誤頁?) – Kenneth 2013-05-08 17:42:15

+0

@Kenneth已經做了,沒有找到它 – Kumar 2013-05-08 17:43:42

+0

D你通過JavaScript或301/302獲得重定向? – Kenneth 2013-05-08 17:44:22

回答

0

看起來你可能有一些路由問題。 RouteConfig.cs文件位於MVC4項目的App_Start文件夾中。其他

一件事,如果你的頁面動作是在不同的控制器比你的HomeController中,那麼你需要的代碼是這樣的:

public ActionResult Index() 
{ 
    return RedirectToAction("OtherController", "Page", new { id = "Home" }); 
} 



我創建了一個基本MVC4項目與重定向你有,它適用於我。用戶通過以下網址結束:HTTP://本地主機:47272 /主頁/頁/首頁]

這裏是我的HomeController.cs

public class HomeController : Controller 
{ 
    // 
    // GET: /Home/ 

    public ActionResult Index() 
    { 
     return RedirectToAction("Page", new { id = "Home" }); 
    } 

    public ActionResult Page(string id) 
    { 
     return View(); 
    } 
} 



這裏是我的RouteConfig.cs

public class RouteConfig 
{ 
    public static void RegisterRoutes(RouteCollection routes) 
    { 
     routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); 

     routes.MapRoute(
      name: "Default", 
      url: "{controller}/{action}/{id}", 
      defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional } 
    ); 
    } 
} 
相關問題