关于此 Attibute路由,当我运行应用程序时,我收到HTTP 404 Not Found结果为什么?。
[Route("custom/route/{id}/{name}")]
public ActionResult Student(int id, string name)
{
return Content(string.Format("id = {0} & name = {1}", id, name));
}
结果:
答案 0 :(得分:0)
确保您的RouteConfig.cs看起来像这样:
public class RouteConfig
{
public static void RegisterRoutes(RouteCollection Routes)
{
Routes.IgnoreRoute("{resource}.ashx/{*pathInfo}");
Routes.MapMvcAttributeRoutes();
Routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
namespaces: new string[] { "YourControllerNamespace.Controllers" },
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
}
}
请注意 Routes.MapRoute
中的命名空间参数