RenderPartial和ViewBag

San*_*ago 3 asp.net-mvc html-helper viewbag

我正在尝试修改此代码:http: //www.codeproject.com/Articles/260470/PDF-reporting-using-ASP-NET-MVC3 使其获取ViewBag数据以呈现PDF中的视图.

基本上,我需要使用新的Context我的ViewBag传递给Html.RenderPartial,现在的代码是:

Html.RenderPartial(viewName, model);
Run Code Online (Sandbox Code Playgroud)

而我正在尝试将其更改为:

Html.RenderPartial(viewName, model, new ViewDataDictionary(ViewBag));
Run Code Online (Sandbox Code Playgroud)

我没有得到任何错误,但字典保持空白.

BR

hea*_*vyd 11

尝试传球 ViewData属性而不是ViewBag.

Html.RenderPartial(viewName, model, new ViewDataDictionary(ViewData));
Run Code Online (Sandbox Code Playgroud)

ViewBag属性是一个动态对象,因此ViewDataDictionary您调用的构造函数是一个object.你最好使用已经填充的那个ViewDataDictionary.ViewBag和ViewData中的数据是相同的.