2015-04-03 95 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实例。

祝你好运