简体   繁体   中英

Can not access a controller (ASP.NET MVC)

This controller:

public class TestController <T> : Controller
{
    public string Index()
    {             
        return "123";
    }
}

This definition of the routes:

routes.MapRoute(
     "Default",
     "{controller}/{action}/{id}",
     new
     {
          controller = "Test<T>",
          action = "Index",
          id = "" 
     });

This is the error I get:

The IControllerFactory 'Yad2.Web.Mvc.UI.Infrastructure.NinjectControllerFactory' did not return a controller for the name 'Test'.

public class TestController <T>   : Controller
{
    public string Index( )
    {             
        return "123";
    }
}

List of things wrong here:

  1. Controllers cannot be generic abstract classes, you need to define T .
  2. All actions need to return ActionResult derived objects.
  3. "Test" in your route definition is absolutely incorrect. Never going to work.
  4. You never showed your Ninject registration.

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