I have a line graph created using Reporting in MVC. But unable to display it using Views. Can someone please help me on how to display rdlc charts in MVC?
Asked
Active
Viewed 1,119 times
2
-
You can't do it without WebForms libraries (So you should add them to project anyway). But if you don't need to interact you can render it as a file (exel for example) and download. – teo van kot Aug 01 '16 at 07:18
-
Thanks teo van kot .. – Bhavana Aug 01 '16 at 10:39
-
@teovankot : I found a way here https://reportviewerformvc.codeplex.com/wikipage?title=Getting%20Started but its not working for me. It says system.web.mvc.htmlhelper dynamic does not contain a definition for 'Report Viewer'..I tried adding namespaces, but still not working – Bhavana Aug 01 '16 at 10:45
-
If you check dependences it uses `MicosoftReportViewerWebForms_v11` so it's webforms component. If you need help with install - create another question with all the details – teo van kot Aug 01 '16 at 10:52
-
@teovankot: I have already installed this in my project, But still there is an issue using report viewer. – Bhavana Aug 01 '16 at 11:02
1 Answers
0
I have tried a different approach... for me, it worked. The first thing you will need to do is:
Add -> Microsoft.ReportingServices.ReportViewerControl.WebForms by Microsoft
***make sure that all the packages are in the 16 version.***
With this package you will only need to add the report, add a dataModel and then bind it to the report dataSet, you will no longer need to have a viewForm.
In this approach you will use the controller for:
.add data (example):
EmpresaEntities emp_entities = new EmpresaEntities();
ReportDataSource emp_datasource = new ReportDataSource("Empresa", (from empresa in emp_entities.FourAll_Empresa select empresa));
viewer.LocalReport.DataSources.Clear();
viewer.LocalReport.DataSources.Add(emp_datasource);
. merge data(exemple):
MergeModels models = new MergeModels();
models._Empresas = (from FourAll_Empresa in emp_entities.FourAll_Empresa select FourAll_Empresa).ToList();
models._Entidades = (from FourAll_Entidade in ent_entidade.FourAll_Entidade select FourAll_Entidade).ToList();
.define the size of a window(example):
viewer.SizeToReportContent = false;
const int ConstantePercentagem = 100;
viewer.Width = Unit.Percentage(ConstantePercentagem);
viewer.Height = Unit.Pixel(800);
viewer.ZoomMode = ZoomMode.FullPage;
.return viewer(exemple):
ViewBag.ReportViewer = viewer;
return View( models);
this will set your report ready with data :)
In the Index.cshtml:
@using ReportViewerForMvc;
@using System.Web.UI.WebControls;
@using System.Web.Mvc;
@{
ViewBag.Title = "Index";
}
@Html.ReportViewer(ViewBag.ReportViewer as Microsoft.Reporting.WebForms.ReportViewer, new { scrolling = "yes", Width = "1200px", Height = "800px" })

Andre Gomes
- 1
- 1