I have following controller , in that controller I created session to save IENUMERABLE
data-set
[HttpPost]
[ValidateInput(false)]
public ActionResult Create_Brochure(IEnumerable<ProductsPropertiesVM> model)
{
IEnumerable<ProductsPropertiesVM> newmodel = model;
IEnumerable<BrochureTemplateProperties> sample = model.Where.....
Session["TemplateData"] = newmodel;
return View(sample);
}
EDIT:
Create_Brchure View page has href link to call PrintIndex
method in same class file
<a href="@Url.Action("PrintIndex", "Brochure")">Download ViewAsPdf</a>
this is PrintIndex
method
public ActionResult PrintIndex()
{
return new Rotativa.ActionAsPdf("Create_Brochure_PDF") { FileName = "TestActionAsPdf.pdf" };
}
I want to use that session list dataset again in Create_Brochure_PDF
controller method,so I created here that method
public ActionResult Create_Brochure_PDF()
{
IEnumerable<ProductsPropertiesVM> newmodel = Session["TemplateData"] as IEnumerable<ProductsPropertiesVM>;
IEnumerable<BrochureTemplateProperties> samplePDF = newmodel.Where(....
return View(samplePDF);
}
but in above method I'm getting null IEnumerable<ProductsPropertiesVM> newmodel
EDIT:
If I explain this whole scenario
Create_Brochure
controller method has a view , Create_Brochure
view as
PDF
PrintIndex
method so in
that action method again its calling to Create_Brochure_PDF
method ,
so I'm getting null object set in Create_Brochure_PDF
I had the same issue some times ago, So I came up with solution ViewasPdf()
method in Rotativa library
You can directly call to once You click that href link but you have to create a View for this method that your going to generate as PDF
So here the steps
Create a Action for the View that your Going to Generate as PDF
public ActionResult Create_Brochure_PDF()
{
IEnumerable<ProductsPropertiesVM> newmodel = Session["TemplateData"] as IEnumerable<ProductsPropertiesVM>;
IEnumerable<BrochureTemplateProperties> samplePDF = newmodel.Where(....
rerurn View();
}
Generate view for that Action method
Replace this line rerurn View();
with following line in Create_Brochure_PDF()
method
return new Rotativa.ViewAsPdf("Create_Brochure_PDF") { FileName = "TestActionAsPdf.pdf" };
Create_Brochure_PDF()
method as follows in
Create_Brochure view page<a href="@Url.Action("Create_Brochure_PDF", "Brochure")">Download ViewAsPdf</a>