2015-04-03 50 views
1

我簡單的Web應用程序與1個默認路由:ASP.NET MVC默認勞斯是錯誤的

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

我控制器包含以下操作:

public class GameController : Controller 
{ 
    public ActionResult Index() 
    { 
     // some actions    
     return View(); 
    }      

    [HttpPost] 
    public ActionResult CreateGame(Game game, User user) 
    { 
     // some actions 
      return View("Game");      
    } 

    [HttpPost] 
    public ActionResult JoinGame(User user) 
    { 
     // some actions 
     return View("Game");       
    } 
} 

此外,根據查看/ GAME文件夾我「索引」和「遊戲」視圖。 但是,當我從時間開始應用時間(不總是!),它要求

http://localhost:55815/Game/Game 

,而不是

http://localhost:55815 or http://localhost:55815/Game/Index 

回答

3

您的應用程序的默認路由是工作的罰款。

調試器啓動url http://localhost:55815/Game/Game,因爲文件Game.cshtml當前在您的Visual Studio中打開。

該解決方案位於您的VisualStudio項目配置中。 選擇具有空值的特定頁面,而不是當前/活動頁面

enter image description here

+1

好吧,我在腦海裏有一件事 - OMG!嚴重!我調試了幾個小時! &%$#^ @ $#$#*%$(^(^%... grrrrr 非常感謝! – 2015-04-03 13:51:20

0

其實,

/遊戲/遊戲

/遊戲/索引

都是一樣的。當你檢查你的默認路由文件時,你可以看到你的主控制器是用預定義的控制器和動作編寫的。所以程序根據這個自動解析這個url。主要嘗試你的web應用程序不在Visual Studio調試,但把它放在IIS下,如果你需要調試,調試IIS實例。

祝你好運