Last active
May 30, 2025 13:13
-
-
Save NikolayIT/151b39bd1fe53804fa83a844b3abc5fb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private readonly IViewRenderService viewRenderService; | |
private readonly IHtmlToPdfConverter htmlToPdfConverter; | |
private readonly IHostingEnvironment environment; | |
public DashboardController( | |
IViewRenderService viewRenderService, | |
IHtmlToPdfConverter htmlToPdfConverter, | |
IHostingEnvironment environment) | |
{ | |
this.viewRenderService = viewRenderService; | |
this.htmlToPdfConverter = htmlToPdfConverter; | |
this.environment = environment; | |
} | |
[HttpGet] | |
public async Task<IActionResult> GetPdf(SomeInputModel input) | |
{ | |
var model = this.GetViewModel(input); | |
var htmlData = await this.viewRenderService.RenderToStringAsync("~/Views/Dashboard/GetPdf.cshtml", model); | |
var fileContents = this.htmlToPdfConverter.Convert(this.environment.ContentRootPath, htmlData); | |
return this.File(fileContents, "application/pdf"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Could not find an IRouter associated with the ActionContext. If your application is using endpoint routing then you can get a IUrlHelperFactory with dependency injection and use it to create a UrlHelper, or use Microsoft.AspNetCore.Routing.LinkGenerator.)