2

I would like to get JSON result from another Controller and pass it back to client, here is the scenario:

using JQuery Client request for JSON from Controller A --> Controller A pass parameter to Controller B and get's JsonResult --> Controller A pass JSON back to Client.

What is the best way to approach this scenario??

Frank Parsons
  • 251
  • 1
  • 4
  • 15

2 Answers2

3

Perfect time to extract functionality from ControllerB to a separate class/method.

public class ControllerB
{
    public JsonResult Action()
    {
        return Foo.Action();
    } 
}
Anton Gogolev
  • 113,561
  • 39
  • 200
  • 288
2

Does Controller A really need to be the one to pass the result back to the client? The client won't know the difference either way. Generally I imagine you would use RedirectToAction to pass the control to Controller B and then the action on Controller B would return the JSON result, no different than if that action were called directly.

Community
  • 1
  • 1
David
  • 208,112
  • 36
  • 198
  • 279
  • It is possible to pass parameter as Object (e.g Person) ? return RedirectToAction("Action", new { person = curPersonObj }); – Frank Parsons Jul 29 '11 at 13:01