简体   繁体   中英

ASP.Net MVC No routes but default are working

I have added a new Controller to my application, and then from there added in a new View (right click, add view on the context menu)

I have added the route to the Route table, but when I browse to it I get a 404 .

I can only assue that this is something fundamental that is wrong, as if I replace the values in the default route, I still cannot access my page.

The route table is;

routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

routes.MapRoute(
    "Classroom",
    "{controller}/{action}/",
    new { controller = "Classroom", action = "Index" }
);


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

there is only a return View() ; in the index method. I have installed Glimpse, but as I am getting a 404, I cannot actually see the url that is being passed back.

So, what techniques / tricks are there I can use to track this down, (and any common gotcha's that could be causing this?)

Visual Studio 2012, using the inbuilt webserver.

This is Fixed. It was a stupid Gotcha on my part. The Controller was Called Classroom not ClassroomController

I have added the route to the Route table

No, you don't need to add any route for that. Get rid of the Classroom route from your Global.asax and leave only the Default one. Now you could safely navigate to your controller using /classroom/index which will render the Index action of the ClassroomController .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM