tags:

views:

137

answers:

3

Hello all,

I am getting the following error while running my MVC application, which uses the json data:

An error occurred while creating a controller of type 'ecom.Controllers.AdminController'. If the controller doesn't have a controller factory, ensure that it has a parameterless public constructor."

Please Suggest some useful answers.

Thanks, Ritz

+2  A: 

If you've provided a non-default constructor for your controller, one which takes parameters, (say, for testing) you need to also provide suitable default, parameterless constructor that doesn't take parameters so that the default controller factory can instantiate your controller. If your controller must have parameters supplied to it and can't use a default, parameterless constructor, then you must implement a controller factory for it that knows how to instantiate it with the parameters.

tvanfosson
+1. Absolutely. I would add if you need to inject something into the controllers, then using something like Unity would be useful.
RichardOD
Or Castle.Windsor, Ninject, StructureMap, Autofac, etc. Just throwing out options.
mannish
@Mannish- yes any will do.
RichardOD
A: 

Try giving it a constructor - public , no parameters

JL
A: 

By default, the class you derive from "Controller" (e.g. "MyController") doesn't have a constructor. If you add one that adds parameters (for whatever reason) then you'll also need a parameterless version. It has nothing to do with json as far as I know.

Mark Brittingham
This is true unless you are using IOC.
RichardOD