c# - Render View in backend dll -
normally use this:
private byte[] getinvoiceaspdf(string id) { var model = utilities.getmodel(id); viewdata.model = model; var view = viewengines.engines.findview(controllercontext, "pdflayout", null); byte[] pdfbuf; using (var writer = new stringwriter()) { var context = new viewcontext(controllercontext, view.view, viewdata, tempdata, writer); view.view.render(context, writer); writer.flush(); string content = writer.tostring(); pdfbuf = utilities.converthtmltopdf(content); if (pdfbuf == null) throw new exception("invalid pdfbuffer when creating pdf file."); } return pdfbuf; }
this works great when inside controller. need move dll file. how can convert , work inside dll file?
the problems controllercontext
, viewdata
/tempdata
. in above set viewdata
directly since inside controller , context controller.
it's still mvc project, logic moved dll file.
posting comment answer:
the solution pass necessary context information controller , other resources function parameters (or pass controller's instance if publicly exposes necessary contexts), , use them in function usual. way function have necessary information accomplish task.
Comments
Post a Comment