gpt4 book ai didi

c# - ASP.NET MVC 默认路由错误

转载 作者:太空宇宙 更新时间:2023-11-03 23:39:52 25 4
gpt4 key购买 nike

我得到了带有 1 个默认路由的简单 Web 应用程序:

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

我的 Controller 包含以下操作:

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");
}
}

同样在 Views/Game 文件夹下,我得到了“Index”和“Game” View 。但是当我不时(不总是!)开始申请时,它会请求

http://localhost:55815/Game/Game 

代替

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

最佳答案

您的应用程序默认路由工作正常。

调试器启动 url http://localhost:55815/Game/Game 因为文件 Game.cshtml 当前在您的 Visual Studio 中打开。

解决方案在您的 VisualStudio 项目配置上。选择具有空值的特定页面而不是当前/事件页面

enter image description here

关于c# - ASP.NET MVC 默认路由错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29433252/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com