Asp.net MVC 5, база данных SQL и веб-форма RDLC reportviewer
Дорогие Все,
Please help me with asp.net mvc and rdlc report viewer. I have a syncfusion tree view page that contain report name from database and print button. I select the report name from tree view and click the print button to print report. I have report controller, model and view. In Report folder of view folder, I have two cshtml page Index and ReportView. And my ReportViewer.aspx web form and other .rdlc reports are in another folder. Because I don't want to open ReportViewer.aspx web form in Index.cshtml under tree view. So I create ReportView.cshtml. Index page for name of report tree view and ReportView page for ReportViewer.aspx web form. But I don't know how to send report name from tree view to ReportView.cshtml and then from ReportView.cshtml to ReportViewer.aspx web form. I want to switch case in code behind of ReportViewer.aspx with report name. Some code of mine is below. Thank you all friends.
Что я уже пробовал:
Вот мой ReportController
public ActionResult Index() { using (conn) { conn.Open(); string query = "Select ReportID, ReportName, IsNull(ParentID, 0) ParentID, IsParent From Report Order By ReportID"; SqlDataAdapter da = new SqlDataAdapter(query, conn); da.Fill(dt); conn.Close(); } List<ReportNameList> reportList = new List<ReportNameList>(); foreach (DataRow rows in dt.Rows) { reportList.Add(new ReportNameList { ReportID = Convert.ToInt32(rows["ReportID"]), ParentID = Convert.ToInt32(rows["ParentID"]), ReportName = rows["ReportName"].ToString(), IsParent = Convert.ToBoolean(rows["IsParent"]), Expanded = Convert.ToBoolean(rows["IsParent"]) }); } ViewBag.DataSource = reportList; return View(); } public ActionResult ReportView() { return View(); }
Вот моя модель
public class ReportNameList { public int ReportID { get; set; } public string ReportName { get; set; } public int ParentID { get; set; } public bool IsParent { get; set; } public bool Expanded { get; set; } } public class ClaimEnqTmp { public DateTime InvDate { get; set; } public string RegNo { get; set; } public string ClaimTypeName { get; set; } public string ClaimantName { get; set; } public string SupplierName { get; set; } public string DepotName { get; set; } public string DeptName { get; set; } public string CurrencyShort { get; set; } public int Amount { get; set; } }
Вот мой индекс.cshtml.
<div style="border:solid thin; border-color:#ecf0f5"> @(Html.EJ().TreeView("reportTree").TreeViewFields(s => s.Datasource((IEnumerable<ReportNameList>)ViewBag.datasource).Id("ReportID").ParentId("ParentID") .Text("ReportName").HasChild("IsParent").Expanded("IsParent"))) </div> <div class="box-footer"> <input type="button" class="btn btn-default" id="btnPrint" style="width:100px" value="Print" onclick="PrintReport()" /> </div>
Вот скрипт в Index.cshtml
<script type="text/javascript"> function PrintReport() { var treeReportList = $("#reportTree").data('ejTreeView'); var rptName = ""; var selectedNode = treeReportList.getSelectedNode(); rptName = treeReportList.getText($(selectedNode[0])); //how to pass rptName to ReportView.cshtml. I don't know yet. var url = '@Url.Action("ReportView", "Report")'; window.location.href = url.replace(); } </script>
Вот страница ReportView.cshtml, и я не знаю, как получить para со страницы индекса и отправить на страницу ReportViewer.aspx.
@{ ViewBag.Title = "Report"; Layout = "~/Views/Shared/_Layout.cshtml"; } <iframe id="myReport" width="100%" height="100%" src="~/Reports/ReportViewer.aspx?ReportName=By%20Date"></iframe>
Вот .CS и HTML из моего элемента управления reportviewer.aspx-страницы.
<body> <form id="formReportViewer" runat="server"> <div> <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager> <rsweb:ReportViewer ID="rvReportViewer" runat="server" Width="100%"> </rsweb:ReportViewer> </div> </form> </body>
Вот код, лежащий в основе ReportViewer.aspx
protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { if(Request.QueryString["ReportName"] != null) { string reportName = Request.QueryString["ReportName"].ToString(); switch (reportName) { case "By Date": using (conn) { conn.Open(); string query = "Select InvDate, RegNo, ClaimTypeName, ClaimantName, SupplierName, DepotName, DeptName, CurrencyShort, Amount From ClaimEnqTmp"; SqlDataAdapter da = new SqlDataAdapter(query, conn); da.Fill(dt); conn.Close(); } List<ClaimEnqTmp> claimEnq = new List<ClaimEnqTmp>(); foreach (DataRow rows in dt.Rows) { claimEnq.Add(new ClaimEnqTmp { InvDate = Convert.ToDateTime(rows["InvDate"]), RegNo = rows["RegNo"].ToString(), ClaimTypeName = rows["ClaimTypeName"].ToString(), ClaimantName = rows["ClaimantName"].ToString(), SupplierName = rows["SupplierName"].ToString(), DepotName = rows["DepotName"].ToString(), DeptName = rows["DeptName"].ToString(), CurrencyShort = rows["CurrencyShort"].ToString(), Amount = Convert.ToInt32(rows["Amount"]) }); } rvReportViewer.LocalReport.ReportPath = Server.MapPath("~/Reports/rptClaimEnq.rdlc"); rvReportViewer.LocalReport.DataSources.Clear(); ReportDataSource rds = new ReportDataSource("ClaimEnqTmpDataSet", claimEnq); rvReportViewer.LocalReport.DataSources.Add(rds); rvReportViewer.LocalReport.Refresh(); rvReportViewer.DataBind(); break; case a: break; case b: break; default: break; } } } }