diyoda_
diyoda_

Reputation: 5420

Asp.Net MVC3 project Controllers and views are not working

This is kind of an odd problem that I am facing most of the time. I am creating a website and I have created a folder inside controllers folder in the project and I have created a controller inside that folder. So far it was Ok.

Then I created a view for that(Not manually)I can even navigate from controller to view in the code(This is to tell that the controller and the view are properly mapped in the code). But when I run the project and go to that URL its not working. It gives the following error. Although this is a more general error I have no thread to follow to get out of this mess.

But all the things that are created earlier is working smoothly. I have even tried a Default controller and created a view for that and then ran the program and it gives the same error.

Now I can not create new controllers and views(I can but they are not working). I am stuck with this all day long :(.

I feel like some configuration is missing. But I can not find out. Since I am new to this I am totally lost. And I can not figure out what to do.

I am totally confused and I have no idea of what has happened. Is it a settings problem in Visual studio?. And what should I do to make this work.

The error is this:

enter image description here

PS: I am working with Team Foundation server and I can not even do debugging. These controller methods are not called.

Upvotes: 0

Views: 206

Answers (1)

Marc
Marc

Reputation: 6771

Have a look into MVC routing and modify your Global.asax.cs with this code:

public class MvcApplication : System.Web.HttpApplication
{
    public static void RegisterRoutes(RouteCollection routes)
    {
        routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

        routes.MapRoute(
            "Default",                                              // Route name
            "{controller}/{action}/{id}",                           // URL with parameters
            new { controller = "Home", action = "Index", id = "" }  // Parameter defaults
        );

    }

    protected void Application_Start()
    {
        RegisterRoutes(RouteTable.Routes);
    }
}

Upvotes: 2

Related Questions