controller: //主视图 public ActionResult spReport() { spXtraReport xrpt1 = new spXtraReport(GetTempDataSet()); xrpt1.DataSource = GetTempDataSet(); ViewData["spReport"] = xrpt1; return View(); } //分布视图 public ActionResult spReportViewerPartial() { spXtraReport xrpt1 = new spXtraReport(GetTempDataSet()); xrpt1.DataSource = GetTempDataSet(); ViewData["spReport"] = xrpt1; return View("spReportViewerPartial"); } //数据源 private DataSet GetTempDataSet() { DataSet ds = new DataSet(); DataTable dt = new DataTable("tempTable"); dt.Columns.Add("test1", Type.GetType("System.String")); dt.Columns.Add("test2", Type.GetType("System.String")); dt.Columns.Add("test3", Type.GetType("System.String")); dt.Columns.Add("test4", Type.GetType("System.String")); dt.Columns.Add("test5", Type.GetType("System.String")); dt.Columns.Add("test6", Type.GetType("System.String")); dt.Columns.Add("test7", Type.GetType("System.String")); DataRow tempRow; for (int i = 0; i < 7; i++)//i:Row { tempRow = dt.NewRow(); tempRow[0] = i.ToString(); tempRow[1] = i.ToString(); tempRow[2] = i.ToString(); tempRow[3] = i.ToString(); tempRow[4] = i.ToString(); tempRow[5] = i.ToString(); tempRow[6] = i.ToString(); dt.Rows.Add(tempRow); } ds.Tables.Add(dt); return ds; } 设计code: //主视图 public ActionResult spReport() { spXtraReport xrpt1 = new spXtraReport(GetTempDataSet()); xrpt1.DataSource = GetTempDataSet();//绑定数据源是用这种还是用下面ViewData方式? ViewData["spReport"] = xrpt1; return View(); } //分布视图 public ActionResult spReportViewerPartial() { spXtraReport xrpt1 = new spXtraReport(GetTempDataSet()); xrpt1.DataSource = GetTempDataSet(); ViewData["spReport"] = xrpt1; return View("spReportViewerPartial"); } //数据源 private DataSet GetTempDataSet() { DataSet ds = new DataSet(); DataTable dt = new DataTable("tempTable"); dt.Columns.Add("test1", Type.GetType("System.String")); dt.Columns.Add("test2", Type.GetType("System.String")); dt.Columns.Add("test3", Type.GetType("System.String")); dt.Columns.Add("test4", Type.GetType("System.String")); dt.Columns.Add("test5", Type.GetType("System.String")); dt.Columns.Add("test6", Type.GetType("System.String")); dt.Columns.Add("test7", Type.GetType("System.String")); DataRow tempRow; for (int i = 0; i < 7; i++)//i:Row { tempRow = dt.NewRow(); tempRow[0] = i.ToString(); tempRow[1] = i.ToString(); tempRow[2] = i.ToString(); tempRow[3] = i.ToString(); tempRow[4] = i.ToString(); tempRow[5] = i.ToString(); tempRow[6] = i.ToString(); dt.Rows.Add(tempRow); } ds.Tables.Add(dt); return ds; } 分布视图: @Html.DevExpress().DocumentViewer(settings => { // The following settings are required for a ReportViewer. settings.Name = "documentViewer1"; settings.Report = (spXtraReport)ViewData["spReport"]; // Callback and export route values specify correspondingcontrollers and their actions. // These settings are required as well. settings.CallbackRouteValues = new { Controller = "spReport", Action = "spReportViewerPartial" }; settings.ExportRouteValues = new { Controller = "spReport", Action = "ExportDocumentViewer" }; }).GetHtml() 我这样写在视图里面报: 无法将类型为“System.Web.Mvc.HtmlHelper`1[System.Object]”的对象强制转换为类型“System.Web.Mvc.HtmlHelper”。
|