I have the following code:
PDFController Ctrl = new PDFController();
byte[] ArquivoPDF = Ctrl.GerarPDF(xml);
This part above is in WebApi, where I create a new instance of the Controller to use the function that is in it. The code below is already the part of the controller:
public class PDFController : Controller
{
public string RenderizaHtmlComoString(string NomeView, object model)
{
ViewData.Model = model;
using (var sw = new StringWriter())
{
var viewResult = ViewEngines.Engines.FindPartialView(ControllerContext, NomeView);
var viewContext = new ViewContext(ControllerContext, viewResult.View, ViewData, TempData, sw);
viewResult.View.Render(viewContext, sw);
viewResult.ViewEngine.ReleaseView(ControllerContext, viewResult.View);
return sw.GetStringBuilder().ToString();
}
}
}
In the part that will form the viewResult variable, it gives an error and says that the ControllerContext can not be null. can anybody help me? * This Controller is not bound to any View.