Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

Basically, I need to pass to Html.RenderPartial with a new Context my ViewBag, the code now is:

Html.RenderPartial(viewName, model);

And I'm trying to change it to something like:

Html.RenderPartial(viewName, model, new ViewDataDictionary(ViewBag));

I don't get any error but the Dictionary keeps empty.

BR

like image 626
Santiago Avatar asked Dec 11 '22 13:12

Santiago


1 Answers

Try passing in the ViewData property instead of the ViewBag.

Html.RenderPartial(viewName, model, new ViewDataDictionary(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.

like image 123
heavyd Avatar answered Dec 29 '22 10:12

heavyd