Is it possible to have 2 controller methods with same name ?
1 Answer
You're referring to controller methods which confuses me what you're talking about. Is it C# class methods or controller actions? Let me answer to both.
Pure C# doesn't allow that
It's not possible to have two methods with identical signature in C#. This means same name and same number of parameters with same types.
public int Calculate(int a, int b) { ... }
public int Calculate(int first, int second) { ... } // compiler ERROR
But Asp.net MVC controller actions allow it
If you're talking about Asp.net MVC controller actions, that's of course possible. Use ActionName attribute to accomplish what you require:
public ActionResult Common() { ... }
[ActionName("Common")]
public ActionResult CommonAgain() { ... } // C# signature differs
But there will have to be some other method selector attribute on one of these for the action invoker to know which one to use when request comes in... As they are you'd have a 404 runtime error. It may be that one should be a regular request action but the other should be executed when Ajax request comes in. Or similar. Some distinction is required.