asp.net MVC giving a controller the name 'AdminController' makes it not work
I am working on a ASP.NET application that uses ASP.NET MVC.
I tried naming one of my controllers "AdminController" meaning I typed "Admin" in the new controller text box and it filled out the controller part all by itself of course. This controller never worked until I changed it's name. If I changed the name to开发者_Go百科 anything else it worked with no problems. I looked inside my Global.asax.cs file where the routes were configured and I found no routes leading to it. I tryed adding a route to this new controller like this:routes.MapRoute("Admin", "calcul/SomeAction",
new { controller = "Admin", action = "SomeAction" });
and it worked but then mysite\admin would only get routed to that specific action.
I renamed the controller to AdminSection and it works but I don't understand why it didn't work before.
Does anyone have any idea
You shouldn't need to create an explicit route for your controller if the default route matches it (controller/action/id).
Also, in the new controller text box you would need to type AdminController rather than just Admin. The MVC framework will look for classes that end with this when looking for possible controllers.
It was me, there was a area named admin that I didn't see. When I excluded it from the project the "adminController" controller started to work
精彩评论