开发者

ASP.NET MVC 3 Basic Routing Issue

开发者 https://www.devze.com 2023-03-24 02:05 出处:网络
Works: http://localhost/ApplicationName/Home/Index http://localhost/ApplicationName/ http://localhost/ApplicationName/AnotherController/

Works:

  • http://localhost/ApplicationName/Home/Index
  • http://localhost/ApplicationName/
  • http://localhost/ApplicationName/AnotherController/

404 Error:

I have an Index view for my Home controller and an Index action. Everything was working fine, then I refactored and changed the application name. Now only the Home controller won't default to the Index view when the action is left out

Here's my RegisterRoutes in Global.asax:

public static void RegisterRoutes(RouteCollection routes)
{
    routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

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

}


There was an empty folder in the application root named Home. The application was going there first for the view. Deleted it, problem solved.

0

精彩评论

暂无评论...
验证码 换一张
取 消