gpt4 book ai didi

visual-studio-2008 - 在 web mvc2 中将报告绑定(bind)到 reportviewer

转载 作者:行者123 更新时间:2023-12-01 15:26:00 24 4
gpt4 key购买 nike

我有 asp.net MVC2 应用程序。我正在使用 VS2008 并希望将生成的报告从我的 Controller 连接到报告查看器。

有什么想法吗?

到目前为止我有这段代码“ 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();
}

和查看页面:

 <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>

最佳答案

您始终可以将 ASP.NET WebForms 与 MVC 结合使用。我想这是唯一的方法。
我给你准备了 sample here .

您可以创建一个文件夹,您将在其中放置您的 asp.net WebForm 和报表 (rdlc)。我已将架构 (xsd) 和数据 (xml) 放在同一个文件夹中,但显然,我猜您将要使用数据库。我已经像这样将路线映射到报告:

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

更新:

我准备了一些code对于 ASP.NET MVC3 (MvcReportViewerMVC3)。
它与 Web 表单上的一些小改动几乎相同:我已经集成了新的 ReportViewer (10),并且我必须将 ScriptManager 添加到同一页面:

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

我也更改了 WebForm 代码,因为 page_load 事件似乎被调用了很多次:

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

希望对您有所帮助。

关于visual-studio-2008 - 在 web mvc2 中将报告绑定(bind)到 reportviewer,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5296485/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com