问题描述
我在我的 .net 核心项目中创建了一个报告查看器。在这里,我创建了用于创建报告的窗体。我想要这样的东西:-首先,我从会话中收集我的数据,然后这些收集的数据通过我的报告查看器并希望在我的桌面上显示此报告。但是当我尝试这个时,我发现了很多不同的错误。
这是我的代码:-
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,Allow null Value,Allow multiple values) 2.ProductId(Intiger,Allow multiple values) 3.Price(Intiger,Allow multiple values) 4.(Intiger,Quantity (Allow multiple values)>
我发现了一个意外错误:-
但我想在桌面上查看数据报告。有什么解决办法。我还是个初学者。请帮忙。
解决方法
编程学习过程的一部分是学习阅读错误。 看看它声明你不能添加相同的值名称 2x
此外,您正在执行异步任务,但您的代码中没有等待。只需从方法标题中删除它
公共 IActionResult 打印()
{
字符串 mimetype = "";
int 扩展 = 1;
var path = $"{this._webHostEnvironment.WebRootPath}\Reports\Report1.rdlc";
Dictionary
List<Shop> shop = HttpContext.Session.Get<List<Shop>>("shop");
for(int i=0;i<shop.Count();i++)
{
parameters.AddWithValue("Name",shop[i].Name);
parameters.AddWithValue("Quantity",shop[i].Quantity);
parameters.AddWithValue("ProductId",shop[i].Id);
parameters.AddWithValue("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);
}