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?
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 !
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With