Reputation: 157
I'm trying to diplay a rdlc report in my MVC project. I created 2 addtional folders :
- one for my dataset
- one containing my rdlc
report file and my webform aspx
file. Below is my code for the Page_Load
event of the webform
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
List<Models.goodcustomers> goodcustomers= null;
using (var dc = new MaDbContext())
{
goodcustomers= dc.goodcustomers.ToList();
ReportViewer1.LocalReport.ReportPath = Server.MapPath("~/RPTReports/goodcustomers.rdlc");
ReportViewer1.LocalReport.DataSources.Clear();
ReportDataSource rdc = new ReportDataSource("MyDataset", goodcustomers);
ReportViewer1.LocalReport.DataSources.Add(rdc);
ReportViewer1.LocalReport.Refresh();
}
}
}
Webform code
<body>
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
<rsweb:ReportViewer ID="ReportViewer1" runat="server" AsyncRendering="false" SizeToReportContent="true">
</rsweb:ReportViewer>
</div>
</form>
</body>
This is not working.... What happens is that when the page opens, it prints the cells FOR ALL the items in List<Models.goodcustomers>
BUT those cells are blank.
Obviously when I was debugging I saw that everything was retrieved from the database. So I guess this is not a database connectio issue
goodcustomers
is a view in my database fro which I have created a Model in my MVC application and I'm using DbContext code first to query the database
Any idea of what is going on ?
ps : to display the Webform in my MVC application I just use an <a>
tag with href pointing to the location of the aspx
file
Upvotes: 1
Views: 467
Reputation: 157
I found a solution on a website. Three things should be done here :
1 : convert goodcustomers
to a DataTable
. Then pass that DataTable
as parameter in ReportDataSource rdc = new ReportDataSource("MyDataset", goodcustomers_converted_to_DataTable);
2 : BIND the data. Add ReportViewer1.DataBind();
right below rdc
instantiation
3 : Step 2 should correct the issue. Now is you want to displace the webform in an MVC cshtml view, use <iFrame>
with src pointing to the aspx webform.
Following those 3 steps solved my problem.
Upvotes: 1