Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pass the value inside Rotativa.ActionAsPdf

I am new asp .net .

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

I am having a normal preview page which is working fine.

The same thing I want to print in 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 });
    }

while running the generate pdf is is showing the error as Object reference not set to an instance of an object.

Can any1 tell how i can pass the empid from generate pdf to IDCardpreview ?

like image 611
Binay Kumar Avatar asked Jan 23 '26 08:01

Binay Kumar


1 Answers

The code should look like this at the generatePDF Action.

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

Rotavita is going into the IdCardPreview action itself, and the conversion from string to int will be at the IdCardPreview Action.

like image 71
Victor.Uduak Avatar answered Jan 27 '26 01:01

Victor.Uduak



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!