Dev mvc对象强制转换错误
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 = i.ToString(); tempRow = i.ToString(); tempRow = i.ToString(); tempRow = i.ToString(); tempRow = i.ToString(); tempRow = i.ToString(); tempRow = 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 = i.ToString(); tempRow = i.ToString(); tempRow = i.ToString(); tempRow = i.ToString(); tempRow = i.ToString(); tempRow = i.ToString(); tempRow = 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.Web.Mvc.HtmlHelper”。
设计code:
public spXtraReport()
{
InitializeComponent();
//
// TODO: Add constructor logic here
//
}
public spXtraReport(DataSet ds)//构造函数重载
{
InitializeComponent();
SetDataBind(ds);
}
private void SetDataBind(DataSet ds)//绑定数据源
{
DataSource = ds;
this.xrTableCell1.DataBindings.Add("Text", DataSource, "test1");
this.xrTableCell2.DataBindings.Add("Text", DataSource, "test1");
this.xrTableCell3.DataBindings.Add("Text", DataSource, "test1");
}
页:
[1]