views:

62

answers:

2

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 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
+1  A: 

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.

adrift
Thanks, worked a charm. The MVC project I created previously used the template project which is why I didn't have this issue. Now I feel like a noob :(
Daniel Draper
Glad I could help. Don't feel bad, we're all noobs; It just depends on the topic :)
adrift
A: 

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.

Darin Dimitrov