2

I am creating a simple empty Controller Default1 in ASP.NET MVC4 VS 2012 but when I run it, it gives error.

My Controller is as follows:

public class Default1Controller : Controller
    {
        //
        // GET: /Default1/

        public ActionResult Index()
        {
            return View();
        }

     }

Following Error is thrown:

[HttpException]: The controller for path '/Default1' was not found or does not     implement IController.
   at System.Web.Mvc.DefaultControllerFactory.GetControllerInstance(RequestContext                 requestContext, Type controllerType)
   at System.Web.Mvc.DefaultControllerFactory.CreateController(RequestContext requestContext, String controllerName)
   at System.Web.Mvc.MvcHandler.ProcessRequestInit(HttpContextBase httpContext,IController& controller, IControllerFactory& factory)
   at System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContextBase httpContext,AsyncCallback callback, Object state)
   at System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContext httpContext,AsyncCallback callback, Object state)
   at System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.BeginProcessRequest(HttpContext context, AsyncCallback cb, Object extraData)
   at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionSep.Execute()
   at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)

RouteConfig:

public class RouteConfig
    {
    public static void RegisterRoutes(RouteCollection routes)
    {
        routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

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

Actually I have been creating controllers before this event but some how what ever controller I creates now is not accessible.

Keren Caelen
  • 1,466
  • 3
  • 17
  • 38
user2521079
  • 33
  • 2
  • 7

1 Answers1

-1
  routes.MapRoute(
                name: "Default",
                url: "{controller}/{action}/{id}",
                defaults: new { controller = "Default1", action = "Index", id = UrlParameter.Optional }
            );
Jaimin
  • 7,964
  • 2
  • 25
  • 32
  • This doesn't solve the problem. The controller is explicitly specified in the question - the asker is not trying to make `Default1` the default controller. – Ant P Jul 08 '13 at 12:36
  • Hi, His controller is `Default1` and he routes the controller is `Home` so his controller source is not found. that's why generate the error. – Jaimin Jul 08 '13 at 12:47
  • No, `Home` is the *default* controller - when the controller is *specified* (as in the question), the default controller is irrelevant. – Ant P Jul 08 '13 at 12:49
  • The problem is not with default controller – user2521079 Jul 08 '13 at 15:36
  • My problem is that whatever controller i creates, throws following error. My idea is somehow Routes are not cofigured properly. – user2521079 Jul 08 '13 at 15:38