MVC 中的 rdlc 在转换为 PDF 时显示单个记录
rdlc in MVC shows single record when convert to PDF
我有一个 customerprofile 列表,想使用 rdlc 控件将其转换为 PDF。现在它只显示一条记录,当转换为 PDF 时。我的控制器动作如下:
public ActionResult CompetitorProfileListFormat(string id)
{
LocalReport lr = new LocalReport();
string path = Path.Combine(Server.MapPath("~/Report"), "CompetitorProfileReport.rdlc");
if (System.IO.File.Exists(path))
{
lr.ReportPath = path;
}
else
{
return View(_customerProfileViewModel.CompetitorProfile());
}
ReportDataSource rd = new ReportDataSource("DsCompetitorReport", _customerProfileViewModel.CompetitorProfile());
lr.DataSources.Add(rd);
lr.Refresh();
string reportType = id;
string mimeType;
string encoding;
string fileNameExtension;
string deviceInfo =
"<DeviceInfo>" +
" <OutputFormat>" + id + "</OutputFormat>" +
" <PageWidth>8.5in</PageWidth>" +
" <PageHeight>11in</PageHeight>" +
" <MarginTop>0.5in</MarginTop>" +
" <MarginLeft>1in</MarginLeft>" +
" <MarginRight>1in</MarginRight>" +
" <MarginBottom>0.5in</MarginBottom>" +
"</DeviceInfo>";
Warning[] warnings;
string[] streams;
byte[] renderedBytes;
renderedBytes = lr.Render(
reportType,
deviceInfo,
out mimeType,
out encoding,
out fileNameExtension,
out streams,
out warnings);
return File(renderedBytes, mimeType);
}
我在视图中列出所有记录并转换为 pdf link 如下所示:
<div style="padding:10px; border:1px solid black">
<div><a href="@Url.Action("CompetitorProfileListFormat", new { id = "PDF" })"> Get Report PDF</a></div>
<div><a href="@Url.Action("CompetitorProfileListFormat", new { id = "Excel" })"> Get Report Excel</a></div>
<div><a href="@Url.Action("CompetitorProfileListFormat", new { id = "Word" })"> Get Report Word</a></div>
<div><a href="@Url.Action("CompetitorProfileListFormat", new { id = "Image" })"> Get Report Image</a></div>
</div>
现在,当我调试时,我在数据集和报告中得到了 5 条记录。但是当我点击转换为 pdf 时,它只显示一条记录,如图
我的 rdlc 文件如下所示:
我的视图显示操作方法如下:
public ActionResult CompetitorProfileListRpt()
{
return View(_customerProfileViewModel.CompetitorProfile());
}
我对我的 rdlc 文件或其他文件有什么调整吗?
谁能帮我做这个....
提前致谢.....
根据您发布的 RDLC 报告的屏幕截图,您似乎将文本框放在了可重复的报告项之外。
您必须使用 List
项目并将您希望为其中的每条记录显示的数据放入其中。因此,将文本框移动到列表的 Rectangle
内。这将 grow/repeat 取决于数据源中的行数。
可以找到很棒的教程 here,我相信选项 #2 正是您想要实现的。
我有一个 customerprofile 列表,想使用 rdlc 控件将其转换为 PDF。现在它只显示一条记录,当转换为 PDF 时。我的控制器动作如下:
public ActionResult CompetitorProfileListFormat(string id)
{
LocalReport lr = new LocalReport();
string path = Path.Combine(Server.MapPath("~/Report"), "CompetitorProfileReport.rdlc");
if (System.IO.File.Exists(path))
{
lr.ReportPath = path;
}
else
{
return View(_customerProfileViewModel.CompetitorProfile());
}
ReportDataSource rd = new ReportDataSource("DsCompetitorReport", _customerProfileViewModel.CompetitorProfile());
lr.DataSources.Add(rd);
lr.Refresh();
string reportType = id;
string mimeType;
string encoding;
string fileNameExtension;
string deviceInfo =
"<DeviceInfo>" +
" <OutputFormat>" + id + "</OutputFormat>" +
" <PageWidth>8.5in</PageWidth>" +
" <PageHeight>11in</PageHeight>" +
" <MarginTop>0.5in</MarginTop>" +
" <MarginLeft>1in</MarginLeft>" +
" <MarginRight>1in</MarginRight>" +
" <MarginBottom>0.5in</MarginBottom>" +
"</DeviceInfo>";
Warning[] warnings;
string[] streams;
byte[] renderedBytes;
renderedBytes = lr.Render(
reportType,
deviceInfo,
out mimeType,
out encoding,
out fileNameExtension,
out streams,
out warnings);
return File(renderedBytes, mimeType);
}
我在视图中列出所有记录并转换为 pdf link 如下所示:
<div style="padding:10px; border:1px solid black">
<div><a href="@Url.Action("CompetitorProfileListFormat", new { id = "PDF" })"> Get Report PDF</a></div>
<div><a href="@Url.Action("CompetitorProfileListFormat", new { id = "Excel" })"> Get Report Excel</a></div>
<div><a href="@Url.Action("CompetitorProfileListFormat", new { id = "Word" })"> Get Report Word</a></div>
<div><a href="@Url.Action("CompetitorProfileListFormat", new { id = "Image" })"> Get Report Image</a></div>
</div>
现在,当我调试时,我在数据集和报告中得到了 5 条记录。但是当我点击转换为 pdf 时,它只显示一条记录,如图
我的 rdlc 文件如下所示:
我的视图显示操作方法如下:
public ActionResult CompetitorProfileListRpt()
{
return View(_customerProfileViewModel.CompetitorProfile());
}
我对我的 rdlc 文件或其他文件有什么调整吗? 谁能帮我做这个.... 提前致谢.....
根据您发布的 RDLC 报告的屏幕截图,您似乎将文本框放在了可重复的报告项之外。
您必须使用 List
项目并将您希望为其中的每条记录显示的数据放入其中。因此,将文本框移动到列表的 Rectangle
内。这将 grow/repeat 取决于数据源中的行数。
可以找到很棒的教程 here,我相信选项 #2 正是您想要实现的。