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

Popular posts from this blog

c++ - OpenCV Error: Assertion failed <scn == 3 ::scn == 4> in unknown function, -

php - render data via PDO::FETCH_FUNC vs loop -

The canvas has been tainted by cross-origin data in chrome only -