Is there a way to change the naming convention for controllers in ASP.NET MVC?
What I want is to name my controllers InicioControlador
instead of InicioController
, or better yet, use a prefix instead of a suffix, and have ControladorInicio
as my controller name.
From what I have read so far, I think I have to implement my own Controller Factory. I would be very grateful if any of you could point me in the right direction.
I decided to dig a bit deeper and found exactly what I was looking for after searching through the MVC source code. The convention for controller names is deep inside the roots of the MVC Framework, especifically in two classes
ControllerDescriptor
andControllerTypeCache
.In
ControllerDescriptor
it is given by the following attribute:In
ControllerTypeCache
it is given by the following methods:Yes, ControllerFactory is the best solution of your problem.
This is my first ControllerFactory - but it is very stupid :) You must use reflection and avoid this ugly switch.