Search code examples
asp.netasp.net-mvcasp.net-corerotativa

Rotativa can't find ActionAsPdf: The type or namespace name 'ActionAsPdf' could not be found when using Rotativa.AspNetCore


I'm using nuget package Rotativa.AspNetCore in my .NET 7.0 web application.

I'm trying to use the ActionAsPdf method to convert my View into PDF,

   public ActionResult PrintAllEmployee()
     {
         var report = new ActionAsPdf("Employees");
         return report;
     }

My problem is that ActionAsPdf is missing

Error CS0246 The type or namespace name 'ActionAsPdf' could not be found (are you missing a using directive or an assembly reference?)

Only ViewAsPdf seems to be available, like if ActionAsPdf was not available in package Rotativa.AspNetCore

I've tried with another testing application, using Rotativa package, and there I can find ActionAsPdf but when I use it like this:

public ActionResult PrintAllEmployee()
    {
            var report = new ActionAsPdf("Employees");
            return report;
    }

I have the error message:

Cannot implicitly convert type 'Rotativa.ActionAsPdf' to 'Microsoft.AspNetCore.Mvc.ActionResult'

I'd like to use the ActionAsPdf method from Rotativa.AspNetCore, if possible

Do you know how can I fix this?

Thanks,


Solution

  • ActionAsPdf is used in Rotativa instead of Rotativa.AspNetCore. It supports in ASP.NET instead of ASP.NET Core.

    You need use ViewAsPdf to print view as pdf.

    public IActionResult Privacy()
    {
        return new ViewAsPdf();
    }