开发者

ASP.NET MVC2 Empty Project Not Loading

My environment consists of Visual Studio 2010 and Windows 7 a few months ago I developed an MVC2 application with no problems however after trying to create a new project recently I received the error below.

I did find the link 开发者_StackOverflow中文版http://support.microsoft.com/kb/894670 but this is not relevant because I am not using IIS for testing, just F5 to get this working :)

Any ideas or help would be appreciated.

Server Error in '/' Application.
--------------------------------------------------------------------------------

The resource cannot be found. 
Description: HTTP 404. The resource you are looking for (or one of its dependencies)  could have been removed, had its name changed, or is temporarily unavailable.  Please review the following URL and make sure that it is spelled correctly. 

Requested URL: /


--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:2.0.50727.4952; ASP.NET Version:2.0.50727.4927


The Empty MVC 2 template application does not define any controllers or views. When you create a new Empty MVC 2 application and immediately run it, you will see the error message you posted.

If you check the Global.asax file, you'll see that the project template automatically registers a default route specifying a default controller named "Home" and a default action named "Index".

To get this to run, right-click on the Controllers folder, then choose Add->Controller... Name the controller "HomeController". You can leave the check box to "Add action methods for Create, Update, Delete..." unchecked.

In the HomeController.cs file, right click in the Index() method and choose Add View...

Leave the View name as "Index", uncheck "Select master page", and then click Add.

In the Index view, you can enter some HTML and run the project; you should now see the page rendered by Index.aspx.

One thing I am not sure of is why your error message lists the .NET Framework version as 2.0. If you still have problems, check the target framework on your project properties.


Make sure that the routes are set properly and that you have default values for a controller and action. For example if you have the following route:

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

Make sure that you have a HomeController with an Index action.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜