Skip to content Skip to sidebar Skip to footer

Renderpartial And Viewbag

I'm trying to modify this code: http://www.codeproject.com/Articles/260470/PDF-reporting-using-ASP-NET-MVC3 To make it to get the ViewBag data for render the View in the PDF. Basic

Solution 1:

Try passing in the ViewData property instead of the ViewBag.

Html.RenderPartial(viewName, model, newViewDataDictionary(ViewData));

The ViewBag property is a dynamic object, so the ViewDataDictionary constructor you are calling is the one that takes a object. You're better off to use the one that takes an already populated ViewDataDictionary. The data in the ViewBag and ViewData are the same.

Solution 2:

You can use:

@Html.Partial(viewName)

In partial viewbag from main view will be accessible.

Ok. If you need render html from partial view to pdf you can use this code:

@{
    var htmlString = Html.Partial(viewName);    
    var pdfData = PdfComposerClass.CreatePdfStaticMethod(htmlString);   
}

Post a Comment for "Renderpartial And Viewbag"