I’m attempting to create a generic controller, ie:
public class MyController<T> : Controller where T : SomeType
{ ... }
However, when I try to use it, I’m running into this error everywhere…
Controller name must end in ‘Controller’
So, my question, Is it possible to make a generic controller in asp.net mvc?
Thanks!
If I understand you properly, what you are trying to do, is route all requests for a given Model through a generic controller of type T.
You would like the T to vary based on the Model requested.
You would like
/Product/Indexto triggerMyController<Product>.Index()This can be accomplished by writing your own
IControllerFactoryand implementing theCreateControllermethod like this: