I have working application in asp.net MVC3. Today when I was working on it in VS2010 I found that none of the action from particular controller are firing. On browsing controller/action I get page not found message. I checked all pages are present (controller, view). Even if I add new action to this controller it is not being called at all. At the same time actions from other controllers are working fine. I can access pages. It’s quite weird and I’m not able to figure out it.
Any help?
Edit:
Controller-action which is not working is http://localhost:7400/Registration/MedicalHistory/0
Code from global.asax
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
// Home and error page
routes.MapRoute("error", "error", new { controller = "Home", action = "Error" });
//Default routing
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Program", action = "Index", id = UrlParameter.Optional }, // Parameter defaults
new string[] { "ASPNETMVCApplication.Controllers" }
);
//Admin routing
routes.MapRoute(
"Admin", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Program", action = "Index", id = UrlParameter.Optional }, // Parameter defaults
new string[] { "ASPNETMVCApplication.Areas.Admin.Controllers" }
);
}
MedicalHistory action:
[HttpGet]
public ActionResult MedicalHistory(int id = 0)
{
//some code
return View()
}
Well first things first you seem to have set up your admin area incorrectly.
To add an area you should have in the root of your MVC project a folder structure Areas/{the name of your area}, e.g. Areas/Admin which contains all the usual Controllers, Views folders.
Inside there you should create a class that inherits AreaRegistration and implements at least the AreaName property and RegisterArea() method.
In Global.asax.cs in your Application_Start() handler the first line should be AreaRegistration.RegisterAllAreas();.
Also it is well worth adding RouteDebug to your app and adding a web.config switch you use in you Application_Start() to either turn route debugging on or off. This is absolutely invaluable when your routes are misbehaving or not getting the action parameters you expect.