Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Server Error in '/' Application in ASP.NET MVC 3 with Razor engine

I just created a new ASP.NET MVC 3 project with the Razor engine. I added a controller to the controller folder, and then at homController.cs I added a view.

The View (index.cshtml) has only this code:

@{
   ViewBag.Title = "Home";
}

<h2>Home</h2>

And when I start debugging it shows me this error:

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:4.0.30319; ASP.NET Version:4.0.30319.225

What's the problem?

like image 504
user2478115 Avatar asked Jun 24 '13 09:06

user2478115


2 Answers

Could you check the App_Start/RouteConfig.cs, you must have this code for a controller called homController.cs :

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

    routes.MapRoute(
        name: "Default",
        url: "{controller}/{action}/{id}",
        defaults: new { controller = "hom", action = "Index", id = UrlParameter.Optional }
    );
}

I suppose, your first controller name isn't 'Home', so you have to change the default controller name !

like image 53
Joffrey Kern Avatar answered Nov 14 '22 22:11

Joffrey Kern


Check your routing entries in Application_Start in global.asax since you're using MVC 3. like "Joffrey Kern" suggested, you need to have the routes configured.

also make sure your controller is named "HomeController" and you have a public method called "Index" that returns an ActionResult object.

like image 31
Tamim Al Manaseer Avatar answered Nov 14 '22 22:11

Tamim Al Manaseer