2012-11-19 62 views
1

我剛創建一個空的應用,增加了一個視圖,控制器和運行它。MVC 3,Asp.net 4 - 在應用錯誤 - 資源無法找到

我收到以下錯誤:

「無法找到該資源。」 描述:HTTP 404.您正在查找的資源(或其某個依賴項)可能已被刪除,名稱已更改或暫時不可用。請檢查以下網址並確保它拼寫正確。

我的代碼: TestController.cs

/
namespace WOSubmittal.Controllers 
{ 
    public class TestController : Controller 
    { 

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

    } 
} 

查看位於下查看測試

Index.cshtml

@{ 
    ViewBag.Title = "Index"; 
} 

<h2>Index</h2> 

我把一個斷點指數()例程,它甚至沒有被擊中。有任何想法嗎?

+0

也許是因爲你的控制器被命名爲TestlController代替的TestController(錯字錯誤?) – darkey

+0

抱歉。它是TestController。 – sarsnake

+0

你有一個HomeControler嗎?你有沒有在global.asax中註冊你的默認路由?你是從Visual Studio運行它還是部署到IIS(本地或遠程)? –

回答

1

public static void RegisterRoutes(RouteCollection routes)

new { controller = "Home", action = "Index", id = UrlParameter.Optional } 

這種變化是:

new { controller = "Test", action = "Index", id = UrlParameter.Optional } 

在你的Global.asax.cs

+0

不要運氣。可能必須像我以前一樣創建一個非空應用程序,因爲這需要太長時間才能解決。 – sarsnake

+0

奇怪的是...我複製了你的錯誤,並用這個改變來解決它.. –

+0

試試我的解決方案,然後點擊項目並選擇「Properties」,點擊「Web」選項卡並選擇「Specific Page」文本框空白.. –

1

變化TestlControllerTestController

當尋找你的控制器視圖,MVC將使用控制器的名稱,無字控制器,試圖解決它的時候。

從你給的代碼,MVC看起來在查看/爲test1,不瀏覽/測試。

+0

我的錯字。它是TestController。對不起 - 只是修復它。 – sarsnake

0

改變這一行的Web.config文件:

<httpRuntime enable="false" targetFramework="4.5"/> 

<httpRuntime enable="true" targetFramework="4.5"/>