I was reading a post about custom controller factory ASP.NET MVC.
Someone explained but I just do not understand how to implement. Here is the post URL In asp.net mvc is it possible to make a generic controller?
They said
You would like
/Product/Index
to triggerMyController<Product>.Index()
This can be accomplished by writing your own IControllerFactory and implementing the CreateController
method like this:
public IController CreateController(RequestContext requestContext, string controllerName)
{
Type controllerType = Type.GetType("MyController").MakeGenericType(Type.GetType(controllerName));
return Activator.CreateInstance(controllerType) as IController;
}
Need a bit more sample code. Just do not understand where to define CreateController
function. Do I need to write this function in base controller?
When request comes like /Product/Index
or /Customer/Index
then how index method can be invoke in base controller?
So looking for guidance for a newbie like me in MVC advance area. thanks