0

我的默认路线非常简单,但是如果没有完全限定整个路线,页面就无法正确加载。

以下是我正在使用的路线:

routes.MapRoute(
    "Default", // Route name
    "{controller}/{action}/{id}", // URL with parameters
    new { controller = "Home", action = "Index" } // Parameter defaults
);

这是 HomeController 中应用程序中的唯一操作:

public ActionResult Index()
{
    return Content("New stuff");
}

使用这些网址:

http://localhost:8081/NewMvc1/

我明白了The incoming request does not match any route.

和:

http://localhost:8081/NewMvc1/Home
http://localhost:8081/NewMvc1/Home/Index

我得到一个 404 Mvc 页面,说它试图用静态文件处理请求。

然而,终于有了一个“完全合格的网址”

http://localhost:8081/NewMvc1/Home/Index/1

我从一个也是唯一一个动作中得到了预期的结果输出。

New Stuff

这似乎根本不对。我也从同一个应用程序中获得了 Failed to Execute Action (不确定这是否相关)。

我已经使用 Phil Haack 的 RouteDebugger 来做到这一点,它指出当缺少可选参数时它与 URL 不匹配,但在提供这些参数时匹配。

4

1 回答 1

0

您缺少id默认值:

new { controller = "Home", action = "Index", id = UrlParameter.Optional }
于 2013-07-15T22:18:25.017 回答