微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

无法将数据从控制器传递到报表查看器

如何解决无法将数据从控制器传递到报表查看器

我在我的 .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:-

enter image description here

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)>

我发现了一个意外错误:-

enter image description here

但我想在桌面上查看数据报告。有什么解决办法。我还是个初学者。请帮忙。

解决方法

编程学习过程的一部分是学习阅读错误。 看看它声明你不能添加相同的值名称 2x

此外,您正在执行异步任务,但您的代码中没有等待。只需从方法标题中删除它

公共 IActionResult 打印() { 字符串 mimetype = ""; int 扩展 = 1; var path = $"{this._webHostEnvironment.WebRootPath}\Reports\Report1.rdlc"; Dictionary 参数 = new 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);

}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。