【发布时间】:2021-04-09 07:35:56
【问题描述】:
我在我的 .net 核心项目中创建了一个报表查看器。在这里,我创建了用于创建报告的 windows 窗体。我想要这样的东西:-首先,我从会话中收集我的数据,然后这些收集的数据通过我的报告查看器并希望在我的桌面上显示此报告。但是当我尝试这个时,我发现了很多不同的错误。
这是我的代码:-
public async Task<IActionResult> Print()
{
string mimetype = "";
int extension = 1;
var path = $"{this._webHostEnvironment.WebRootPath}\\Reports\\Report1.rdlc";
Dictionary<string, string> parameters = new Dictionary<string, string>();
List<Shop> shop = HttpContext.Session.Get<List<Shop>>("shop");
for(int i=0;i<shop.Count();i++)
{
parameters.Add("Name", shop[i].Name);
parameters.Add("Quantity", shop[i].Quantity);
parameters.Add("ProductId", shop[i].Id);
parameters.Add("Price", shop[i].Price);
}
LocalReport localReport = new LocalReport(path);
var result = localReport.Execute(RenderType.Pdf, extension, parameters, mimetype);
var r = File(result.MainStream, "application/pdf");
return View(r);
}
Report1.rdlc:-
1.Name(Text,允许空值,允许多个值) 2.ProductId(Intiger,允许多个值) 3.Price(Intiger,允许多个值) 4.(Intiger,Quantity (允许多个值)
我发现了一个意外错误:-
但我想在我的桌面上查看我的数据报告视图。有什么解决办法。我还是个初学者。请帮忙。
【问题讨论】:
-
我想开始从参数参数中删除引号。Add("Name", "shop[i].Name");应该是 parameters.Add("Name", shop[i].Name);
-
现在的错误是什么?
-
我相信您应该使用
DataSource属性。您已将参数声明为Dictionary,但随后您尝试使用相同的键添加多个项目。这行不通。研究使用DataSource代替。
标签: c# asp.net-mvc asp.net-core asp.net-core-mvc rdlc