How to achieve a dynamic controller and action method in ASP.NET MVC?

Absolutely! You’ll need to override the DefaultControllerFactory to find a custom controller if one doesn’t exist. Then you’ll need to write an IActionInvoker to handle dynamic action names. Your controller factory will look something like: public class DynamicControllerFactory : DefaultControllerFactory { private readonly IServiceLocator _Locator; public DynamicControllerFactory(IServiceLocator locator) { _Locator = locator; } protected override … Read more

Getting All Controllers and Actions names in C#

The following will extract controllers, actions, attributes and return types: Assembly asm = Assembly.GetAssembly(typeof(MyWebDll.MvcApplication)); var controlleractionlist = asm.GetTypes() .Where(type=> typeof(System.Web.Mvc.Controller).IsAssignableFrom(type)) .SelectMany(type => type.GetMethods(BindingFlags.Instance | BindingFlags.DeclaredOnly | BindingFlags.Public)) .Where(m => !m.GetCustomAttributes(typeof( System.Runtime.CompilerServices.CompilerGeneratedAttribute), true).Any()) .Select(x => new {Controller = x.DeclaringType.Name, Action = x.Name, ReturnType = x.ReturnType.Name, Attributes = String.Join(“,”, x.GetCustomAttributes().Select(a => a.GetType().Name.Replace(“Attribute”,””))) }) .OrderBy(x=>x.Controller).ThenBy(x => x.Action).ToList(); If … Read more