【发布时间】:2013-03-20 19:03:54
【问题描述】:
我正在尝试创建自定义路由,但无法使其正常工作,即使一切正常,它总是返回 404。
所以这里是定义的路线。
它在默认值之前首先定义,根据路由调试器,这是被命中的路由。(Matched Route: Game/{id}/{title})
routes.Add(
"GamesDefault",
new Route("Game/{id}/{title}",
new RouteValueDictionary(new { controller = "Games", action = "ShowGame" }),
new DefaultMvcRouteHandler(urlTranslator, urlFoundAction)));
这是我试图到达的路径:/Game/5/test
这是控制器声明。 GamesController 位于 Controllers 文件夹中,其视图位于 Views/Games/showGames.cshtml 中。
public GamesController()
{
}
public ActionResult ShowGames(int id, string title)
{
return View(title);
}
DefaultMvcRouteHandler 没有做任何花哨的事情。
public class DefaultMvcRouteHandler : IRouteHandler
{
public IHttpHandler GetHttpHandler(RequestContext requestContext)
{
return new MvcHandler(requestContext);
}
}
默认路由没有问题,我已经尝试了我能找到的一切,比如更改路由的名称,使其与任何文件夹或类似的东西不匹配。 如果有人对更多尝试有任何想法,我将不胜感激。
【问题讨论】:
-
您正在传递“Games”和“ShowGame”的默认路由值,但您的控制器称为“GamesController”,操作方法称为“ShowGames”。
-
omg,我知道它是这样的,但我就是找不到它,已经在这几个小时了。非常感谢
标签: c#-4.0 asp.net-mvc-4 routes