0
我已經添加了一個新的控制器,「LoggingController」到已經有幾個控制器的MVC 4應用程序。 現在我注意到,該控制器的路由行爲與已經存在的路由行爲不同。ASP.NET MVC 4:一個控制器路由不像其他
例如,以下兩個url正常工作,並按下BlogController中的「Index」方法。
http://localhost:56933/Blog/
http://localhost:56933/Blog/Index
那麼做,除非一個我添加的所有其他控制器:
http://localhost:56933/Logging/Index
- 工作正常,打在LoggingController
http://localhost:56933/Logging/
「索引」 的方法 - 返回「服務器錯誤 '/' 應用。 沒有找到您要查的資源。」
我應該從哪裏開始尋找,超越了顯而易見的事物?
這裏是LoggingController
public ActionResult Index(int? page, string Period, string LoggerProviderName, string LogLevel, int? PageSize)
指數的簽名沒有什麼具體在圖路線一定的控制。以下是完整的RouteConfig供參考:
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
routes.MapRoute(
name: "Display",
url: "Post/{id}/{seofriendly}",
defaults: new { controller = "Post", action = "Display", id = UrlParameter.Optional, seofriendly = ""}
);
routes.MapRoute(
name: "SEOFriendly",
url: "{controller}/{action}/{id}/{seofriendly}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional, seofriendly = "" }
);
routes.MapRoute(
name: "SEOFriendlyNoId",
url: "{controller}/{action}/{seofriendly}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional, seofriendly = "" }
);
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
}
我明白了!我選擇了默認值。奇怪的是,當我剛剛修改索引方法時,這還不夠。當我放棄並重新創建控制器+索引時,它開始按預期工作。無論如何,現在都很好。 – Evgeny 2013-03-05 23:50:29