【问题标题】:Subfolder for MVC route not workingMVC 路由的子文件夹不起作用
【发布时间】:2013-12-15 14:25:16
【问题描述】:

我有一个控制器 Foo 和一个操作栏。
唯一路线:

routes.MapRoute(
    name: "foo",
    url: "foo",
    defaults: new { controller = "Foo", action = "Bar" }
);

URL localhost://foo 运行良好;

如果我这样改变路线:

routes.MapRoute(
    name: "foo",
    url: "api/foo",
    defaults: new { controller = "Foo", action = "Bar" }
);

然后 localhost://api/foo 不起作用。

为什么? 我确定某处有问题重复,但我找不到。请指教。

【问题讨论】:

  • 你还有其他路由定义吗
  • @Shyju 没有。我特地创建了一个全新的应用程序,只放了这条路线。
  • @Shyju 我终于找到了问题所在。把答案贴在下面。

标签: asp.net asp.net-mvc


【解决方案1】:

这是我的堕落。
在 global.asax 的 Application_Start 中有一行:

WebApiConfig.Register(GlobalConfiguration.Configuration)

它覆盖了我的“api”路径。

【讨论】:

    【解决方案2】:

    试试url: "~/api/foo"

    看到这个

    Controller in Sub Folder

    MVC Routing: Creating sub folders

    【讨论】:

      猜你喜欢
      • 2013-01-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-03-02
      • 2014-10-05
      • 1970-01-01
      • 2017-02-28
      • 1970-01-01
      相关资源
      最近更新 更多