.NET MVC Call method on different controller

前端 未结 7 1418
Happy的楠姐
Happy的楠姐 2020-11-30 06:26

Can anybody tell me how to call a method on a different controller from within an action method? I don\'t want to redirect. I want to call a method on a different controller

7条回答
  •  无人及你
    2020-11-30 06:50

    Could you just instantiate the controller in your action method and call the other method you need?

    public ActionResult YourActionMethod()
    {
       SomeController c = new SomeController();
       ActionResult result = c.SomeMethod();
    
       return View();
    }
    

提交回复
热议问题