How to pass value inside Rotativa.ActionAsPdf

I am new asp.net.

I am using Rotativa to turn a Razor view to PDF.

I have a normal preview page that works fine.

The same thing that I want to print to PDF.

       [HttpGet]
    public ActionResult IdCardPreview(string empid)
    {

        int empid1 = Convert.ToInt32(empid);
        var dataList = db.mstEmpInformations.Where(x => x.intEmpId == empid1).SingleOrDefault();

        return View(dataList);
    }


   public ActionResult GeneratePDF(string empid)
    {
        int empid1 = Convert.ToInt32(empid);

        return new Rotativa.ActionAsPdf("IdCardPreview", new { empid1 });
    }

      

when running generate pdf, it shows error as Object reference not set to object instance.

Can any1 tell how can I pass empid from pdf file to IDCardpreview?

+3


source to share


1 answer


The code should look like the one shown in the ActionPDF Action.

public ActionResult GeneratePDF(string empid)
{
    return new Rotativa.ActionAsPdf("IdCardPreview", new { empid = empid });
} 

      



Rotavita itself goes into the IdCardPreview action, and the string to int conversion will go into the IdCardPreview action.

+1


source







All Articles