2012-06-27 23 views
0

我正在開發ASP.NET MVC3應用程序。應用程序啓動時Home索引不加載

在視圖中,我創建了一個名爲Home的文件夾和一個名爲Index的視圖。

然後我創建了一個Controller HomeController。

在我添加了控制器:

public ActionResult Index() 
    { 
     return View(); 
    } 

但是當我運行的應用程序,我得到這個錯誤:

The resource cannot be found. 
Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please review the following URL and make sure that it is spelled correctly. 

Requested URL:/

如果我添加到地址欄:/首頁/索引視圖負荷一般。

如何使應用程序在加載時自動進入主頁/索引?

感謝所有幫助

+0

聽起來像你需要在Global.asax文件中註冊一個路由。 –

+0

@PatrickPitre就是這樣!我不能相信我錯過了!!非常感謝。只是寫它作爲答案,我會接受它 – Youssef

+0

看起來像重複http://stackoverflow.com/questions/6554561/troubleshooting-the-resource-cannot-be-found-error – HatSoft

回答

1

您需要添加路由到指向您的路徑Global.asax文件。

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