2

I am having two controller. 1st controller having parameterized constructor and some methods. Now I have to call that methods in my another controller. is there any way to do it?

Below is code

public partial class oneController : Controller
{
   private readonly IEmployeeService _employeeService;
   public oneController(IEmployeeService employeeService)
   {
      this._employeeService = employeeService;
   }

   // some methods


}

public partial class twoController : Controller
{
  // Need to call some methods from oneController
}
mmushtaq
  • 3,430
  • 7
  • 30
  • 47
Jatin Gadhiya
  • 1,955
  • 5
  • 23
  • 42

1 Answers1

0

You can achieve this as follow:

public partial class twoController : Controller{
     oneController  one = new oneController();
     one.AnyMethod(AnyParam);
}

But you're trying to do something the controllers aren't designed for. if you have some common method which is being accessible from multiple controllers then create required method as an public method in some class and invoke from any controller/actions you want.

mmushtaq
  • 3,430
  • 7
  • 30
  • 47