RenderPartial和ViewBag [英] RenderPartial and ViewBag

查看:105
本文介绍了RenderPartial和ViewBag的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试修改以下代码: http://www.codeproject.com/Articles/260470/PDF-reportingusing-ASP-NET-MVC3 要获取ViewBag数据以在PDF中呈现视图.

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.

基本上,我需要将ViewBag的新上下文传递给Html.RenderPartial,现在的代码是:

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

推荐答案

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

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

ViewBag属性是一个动态对象,因此您正在调用的ViewDataDictionary构造函数是采用object的构造函数.您最好使用已经填充了ViewDataDictionary的代码. ViewBag和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.

这篇关于RenderPartial和ViewBag的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆