error running asp.net mvc 2 project out of the box in vs 2010

后端 未结 3 960
既然无缘
既然无缘 2021-01-18 21:50

i created a new solution and it builds fine targeting framework 4.0 but when i run it, my browser comes up saying:

The resource cannot be found. Description:

3条回答
  •  旧巷少年郎
    2021-01-18 22:33

    You don't need to add the default.aspx page described above.

    The browser will display this 404 message if you add and run a new Empty ASP.NET MVC 2 application "out of the box".

    This is because of the default route that is defined in global.asax.

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

    You can see it is looking for a controller called Home and an action called Index.

    When creating a new empty project it's left to you to create the Home controller and Index action (they are not there in an empty project), then create the view for the Index action too.

提交回复
热议问题