Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can we call the Method of a controller from another controller in asp.net MVC?

Tags:

asp.net-mvc

Can we call the Method of a controller from another controller in asp.net MVC?

like image 538
SAHIL SINGLA Avatar asked May 26 '10 07:05

SAHIL SINGLA


People also ask

How can we call controller method from another controller in ASP.NET MVC?

Try this. I'm assuming you want to return that action's result. var ctrl= new MyController(); ctrl. ControllerContext = ControllerContext; //call action return ctrl.


1 Answers

You could also simply redirect straight to the method like so:

public class ThisController 
{
    public ActionResult Index() 
    {
       return RedirectToAction("OtherMethod", "OtherController");
    }
}
like image 83
Nick Masao Avatar answered Sep 27 '22 17:09

Nick Masao