ASP.NET MVC'在Microsoft.Reporting.WebForms.LcalReport.InternalRender进行本地报表处理期间发生错误'

时间:2019-09-18 18:51:02

标签: asp.net-mvc reporting

这是我第一次在ASP.Net上使用Reports,我首先尝试获取一个简单的表作为测试,但最终出现了错误。 我使用了从here找到的代码 当然,我修改了一下 这是VIEW代码:

@using System.Data
@model DataTable
@{
    ViewBag.Title = "ListQuestionnaire";
    Layout = "~/Views/Shared/_Layoutadmin.cshtml";
}

<h2 style="margin-top:30px; margin-bottom : 50px;"> Liste Des Questionnaires</h2>
<div class="table-responsive-sm" style="height:300px;overflow-y:scroll">
    <table class="table">
        <tbody>
            @foreach (DataRow row in Model.Rows)
            {
                <tr id="norme">
                    <td style="width:35%;">@row["titre"]</td>
                    <td style="width:35%;">
                        Etat : @row["etat"]
                    </td>
                    <td>
                        <button class="btn" id="supp" onclick="location.href='@Url.Action("Report", "Rapport",new {id= "PDF"})'"><i class="fa fa-file-pdf-o" aria-hidden="true"></i> Rapport</button>
                        <button class="btn" id="supp" onclick="analyse(@row["id_quest"]);"><i class="fa fa-paper-plane" aria-hidden="true"></i> Envoyer</button>
                    </td>

                </tr>
            }
        </tbody>
    </table>

</div>

这是我从链接代码中获得的方法(唯一的区别是我直接连接到数据库而不是使用EF ENTITIES):

 public ActionResult Report(string id)
            {
                LocalReport lr = new LocalReport();
                string path = Path.Combine(Server.MapPath("~/Reports"), "Report.rdlc");
                if (System.IO.File.Exists(path))
                {
                    lr.ReportPath = path;
                }
                else
                {
                    return RedirectToAction("ListQuest");
                }
                SqlConnection con = new 
SqlConnection(WebConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString);
                    DataTable dt = new DataTable();
                    con.Open();
                    SqlCommand cmd = new SqlCommand("select * from Actions ", con);
                using (SqlDataReader dr = cmd.ExecuteReader())
                {
                    dt.Load(dr);
                }
                List<DataRow> list = dt.AsEnumerable().ToList();
                ReportDataSource rd = new ReportDataSource("MyDataset", list);
                lr.DataSources.Add(rd);
                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;
                try
                {
                    renderedBytes = lr.Render(
                        reportType,
                        deviceInfo,
                        out mimeType,
                        out encoding,
                        out fileNameExtension,
                        out streams,
                        out warnings);

                    return File(renderedBytes, mimeType);
                }catch(Exception ex)
                {
                    MessageBox.Show("error rapport : " + ex.Message + ", " + ex.StackTrace);
                    return RedirectToAction("ListQuest");
                }
            }

图像ERROR ENCOUNTRED显示了我遇到的错误类型,我对其进行了跟踪,并在此处停止:

renderedBytes = lr.Render(
                        reportType,
                        deviceInfo,
                        out mimeType,
                        out encoding,
                        out fileNameExtension,
                        out streams,
                        out warnings);

                    return File(renderedBytes, mimeType);

我真的希望你能帮助我

0 个答案:

没有答案