6

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?

6
  • I would imagine your route is wrong - what is the name of your controller? Commented Jun 24, 2013 at 9:21
  • homController.cs is the name of the controller... the route when i debug it is: http://localhost:13628/ and it isn't workign! Commented Jun 24, 2013 at 9:23
  • When i create an asp.net Web application (without MVC) and debug it, it works perfectly.... I don't know why the error is comming up ! Commented Jun 24, 2013 at 9:25
  • In the question you say the controller is called controller.cs and in the comment you say it's homeController.cs. Which one is it as it could be the cause? Commented Jun 24, 2013 at 9:28
  • @Tanner, sorry mistake :( Commented Jun 24, 2013 at 9:31

6 Answers 6

7

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 !

Sign up to request clarification or add additional context in comments.

4 Comments

can you please tell me where to find App_Start/RouteConfig.cs ??? I looked every folder in the solution explorer but I can't find that what you are saying!
I went to the Global.asax, and found the code that you todl me.... what should I change?? the name of my controller is: homController.cs
If the name of you controller is homController, you have to change the value of the default controller to 'hom'. I have update my answer
thnx joffrey... your answer helpedme :D:D Thnx very much :D
2

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.

Comments

2

In ASP .NET MVC 3 your routes are defined in the global.asax

You can find that in the website root.

By default it looks like this:

public static void RegisterRoutes(RouteCollection routes)
{
    routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
    routes.MapRoute(
      "Default", // Route name
      "{controller}/{action}/{id}", // URL with 
      new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
    );
}

This means when you call the website root with no parameters, it uses the default values - in this case home/index.

So you need to make sure you:

  • have a controller called home
  • an Action called index that returns an ActionResult

Alternatively you can update the default values in the routes, although if you are just starting out I would not recommend this.

Comments

0

It doesn't have to be your routes ... It could be faulty configurations in web config

Comments

0

If you getting this error I highly recommending you to change your public class name. Give a new name as a "HomeController":

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace MyFirstMVC.Controllers
{
    public class HomeController : Controller
    {

        // GET: /First/

        public string Index()
        {
            return  "Jay Swaminarayan"; // this string will be display at your run time!!!
        }

    }
}

Comments

-2

THis is ravinder akula

Please find this answer

  • Right click on your mvc project

  • Choose "Properties"

  • Select the "Web" tab

  • Select "Specific Page"

  • Assuming you have a controller called HomeController and an action method called Index, enter "home/index" instead of home/index.cshtml in to the text box corresponding to the "Specific Page" radio button.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.