获取 ArgumentNullException:值不能为 null。 (参数“RotativaPath”)使用Rotativa将Html视图导出为PDF时

问题描述 投票:0回答:1

我正在使用 Visual Studio 2022 版本 17.7.5 开发 .NET 7.0 Web 应用程序

我需要将 Html 视图转换为 PDF。

为此,我想使用Rotativa,这似乎是一个非常强大且简单的使用工具。

我在网上跟踪了几个教程(它们没有丢失!!),一切看起来都很简单。

我在虚拟应用程序上运行了一些测试,因此其中没有什么复杂的,我只是想转换index.cshtml文件。

我已经安装了 Rotativa.AspNetCore 1.3.2 beta nuget 包,

我还在我的解决方案中安装了 wkhtmltopdf 工具。

这是我的控制器:

    [HttpGet]
public IActionResult Index()
{
    _index = new List<Customer>()
    {
        new Customer {CustomerId = 1, FirstName = "Jimi",
        LastName = "Hendrix" },
        new Customer {CustomerId = 2,FirstName = "Mitch", LastName = "Mitchell"}
    };
    return View(_index);
}


public ActionResult Print()
{
    return new ViewAsPdf("Index", _index);
}

索引视图:

@Html.ActionLink("Print", "Print", "home")

使用此代码,我收到以下错误消息:

ArgumentNullException:值不能为空。 (参数“RotativaPath”)

我搜索了整个网络,谷歌和 Stackoverflow 似乎都没有解决方案。

我不知道 Rotativa 是否存在兼容性问题、设置配置错误或丢失,或者 appsettings.json 存在问题,但到目前为止我所尝试的一切都失败了...

甚至 ChatGPT 也建议我向 Stackoverflow 寻求帮助。

有人有帮助提示吗?

asp.net-mvc pdf-generation wkhtmltopdf rotativa
1个回答
0
投票

我是包裹主人。

您必须将其添加到 Program.cs 中:

app.UseRotativa();

说明位于 Github 存储库页面 https://github.com/webgio/Rotativa.AspNetCore。我会将其粘贴到包自述文件中。

© www.soinside.com 2019 - 2024. All rights reserved.