结合报告的Web MVC2的ReportViewer [英] bind report to reportviewer in web mvc2

查看:111
本文介绍了结合报告的Web MVC2的ReportViewer的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有asp.net MVC2应用。
我使用VS2008,想从我的控制器的ReportViewer挂钩生成的报告。

什么想法?

到目前为止

我有这个code
控制器

  //应该通过数据报告
 公众的ActionResult GenerateReport()
      {
        LocalReport报告=新LocalReport();
        report.ReportPath =使用Server.Mappath(〜/报告/ KingsCourt.rdlc);        清单< InvoiceRow>行=新的List< InvoiceRow>();        rows.Add(新InvoiceRow {名称=检测项目,值=(十进制)25.85});
        rows.Add(新InvoiceRow {名称=测试ITEM2,值=(十进制)5.15});
        ReportDataSource源=新ReportDataSource(InvoiceRow行);
        report.DataSources.Add(源);        计算机[InvoiceRow] =报告;
        返回查看();
      }

和查看网页:

 <表ID =form1的=服务器>  < H2> GenerateReport< / H>
  < rsweb:ID的ReportViewer =ReportViewer1=服务器FONT-名称=宋体
      FONT-SIZE =8PTHEIGHT =400像素WIDTH =400像素>
    < LocalReport ReportPath =报告\\ KingsCourt.rdlc>
      <数据源>
        < rsweb:ReportDataSource的DataSourceID =ObjectDataSource1NAME =InvoiceRow/>
      < /数据源>
    < / LocalReport>
  < / rsweb:&的ReportViewer GT;  < ASP:ObjectDataSource控件ID =ObjectDataSource1=服务器SelectMethod =行
      类型名=Accounts.Classes.Invoices>< / ASP:ObjectDataSource控件>
 < /表及GT;


解决方案

您可以随时使用ASP.NET的WebForms与MVC。我想这是做的唯一途径。结果
我有prepared样本为您这里

您可以创建你要去的地方把你的asp.net web窗体和报表(RDLC)的文件夹。
我已经把在同一个文件夹中的架构(XSD)和数据(XML),但是,很明显,我想你要使用的数据库。
我已经制定了路线的报告(S)是这样的:

  //自定义报表路线
    routes.MapRoute(
     ReportRoute
     报告/ {} REPORTNAME
     〜/报告/ {} REPORTNAME的.aspx
     );

更新:

我有prepared一些<一个href=\"https://skydrive.live.com/redir.aspx?cid=669adf1af64df389&resid=669ADF1AF64DF389!155\">$c$c对于ASP.NET MVC3(MvcReportViewerMVC3)。结果
这是pretty与很多WebForm上的一些细微的变化是一样的:我已经集成了新的ReportViewer(10),我不得不使用ScriptManager添加到同一页:

 &LT; ASP:的ScriptManager ID =ScriptManager1=服务器&GT;&LT; / ASP:ScriptManager的&GT;

我已经改变了的WebForm code以及原因似乎Pa​​ge_Load事件被称为次负载:

 保护无效的Page_Load(对象发件人,EventArgs的发送)
{
    如果(!this.IsPostBack)
    {
    ....
    }
}

希望它帮助。

I have asp.net MVC2 application. I am using VS2008 and want to hook up generated report from my controller to reportviewer.

any ideas?

so far i have this code "Controller"

//should pass data to report
 public ActionResult GenerateReport()
      {


        LocalReport report = new LocalReport();
        report.ReportPath = Server.MapPath("~/Reports/KingsCourt.rdlc");

        List<InvoiceRow> rows = new List<InvoiceRow>();

        rows.Add(new InvoiceRow { name = "Testing item", value = (decimal)25.85 });
        rows.Add(new InvoiceRow { name = "Testing item2", value = (decimal)5.15 });
        ReportDataSource source = new ReportDataSource("InvoiceRow", rows);
        report.DataSources.Add(source);

        ViewData["InvoiceRow"] = report;
        return View();
      }

and View page:

 <form id="form1" runat="server">

  <h2>GenerateReport</h2>
  <rsweb:ReportViewer ID="ReportViewer1" runat="server" Font-Names="Verdana" 
      Font-Size="8pt" Height="400px" Width="400px">
    <LocalReport ReportPath="Reports\KingsCourt.rdlc">
      <DataSources>
        <rsweb:ReportDataSource DataSourceId="ObjectDataSource1" Name="InvoiceRow" />
      </DataSources>
    </LocalReport>


  </rsweb:ReportViewer>    

  <asp:ObjectDataSource ID="ObjectDataSource1" runat="server" SelectMethod="Rows" 
      TypeName="Accounts.Classes.Invoices"></asp:ObjectDataSource>
 </form>

解决方案

You can always use ASP.NET WebForms with MVC. I guess this is the only way to do it.
I've prepared a sample for you here.

You can create a folder where you're going to put your asp.net WebForm and the report (rdlc). I've put in the same folder the schema (xsd) and the data (xml) but, obviously, I guess you're going to use the database. I've mapped the route to the report(s) like this:

    //Custom route for reports
    routes.MapRoute(
     "ReportRoute",
     "Reports/{reportname}",                
     "~/Reports/{reportname}.aspx"
     );

UPDATE:

I have prepared some code for ASP.NET MVC3 (MvcReportViewerMVC3).
It is pretty much the same with some minor changes on the webform: I've integrated the new ReportViewer (10) and I had to add the ScriptManager to the same page:

<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>

I've changed the WebForm code as well cause it appears that page_load event is called loads of times:

protected void Page_Load(object sender, EventArgs e)
{
    if (!this.IsPostBack)
    {
    ....
    }
}

Hope it helps.

这篇关于结合报告的Web MVC2的ReportViewer的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆