If I'm understanding correctly, you're looking to get the result from a controller, and return that through an API controller. The problem with that is that a controller action generally returns an ActionResult
object, not just a string of HTML. There are many types of ActionResult
that would be hard to handle, or would have to be special-cased, such as FileStreamResult
, RedirectResult
, ContentResult
, etc. This is also complicated by the fact that a controller transparently handles applying the returned ActionResult
. It doesn't simply write the result to the response output, but actually applies the ActionResult
to a ControllerContext
by running the ActionResult
's ExecuteResult()
method. If you really needed to do this, and were willing to accept the numerous possible ActionResult
subclasses and handle each one of them, I believe you could create a temporary ControllerContext
and use ExecuteResult()
on it, but I think you'll find that this is a lot of work for little return.
If you're looking to just return HTML (ie, not trying to embed the result in JSON/XML), then you can simply use @Html.Sitecore.Rendering()
within your view pointing towards the rendering item which represents the controller in the compiled DLL, which will render that rendering (and therefore go through the other controller). See here for how to do that: https://ctor.io/specify-datasource-item-of-a-statically-binded-rendering/
Finally, I just want to bring up that you shouldn't be using /api/sitecore
. This is actually a route that's configured in the Speak configuration IIRC, and is actually supposed to be disabled on CD machines if you follow Sitecore's suggestions on configuring the machines. Instead, you should register your own custom route in the initialize pipeline. This is easy to do, and is a better practice. See here for more info: https://doc.sitecore.net/sitecore_experience_platform/developing/developing_with_sitecore/mvc/use_mvc_routing
Edit
If you're able to ensure that you get a ViewResult back from the other controller, you can do something like the following to render the returned view to a string, which you can then manipulate as you wish. It's hard to give you perfect code since you're still at the planning stage, but if you need to go this route, something like this should work. Note that I took some inspiration from here: https://stackoverflow.com/questions/483091/render-a-view-as-a-string
public ActionResult MyMethod() {
var param1 = 1;
var param2 = "test";
var controller = new MyOtherController{ControllerContext = ControllerContext};
var viewResult = (ViewResult)controller.Display(param1, param2);
var result = string.Empty;
using (var sw = new StringWriter())
{
var viewData = new ViewDataDictionary(viewResult.Model);
var tempData = new TempDataDictionary();
var viewContext = new ViewContext(ControllerContext, viewResult.View, viewData, tempData, sw);
viewResult.View.Render(viewContext, sw);
result = sw.GetStringBuilder().ToString();
}
// Do something with result
return Content(result);
}