Having a problem with an embedded rdlc report in an mvc 4 app. Finally got it working, but it's only showing the 1st record. The report uses a sql server view and I've verified that the List<> is passing multiple records, and I have no grouping in the
report. Here's the code...
public ActionResult Report()
{
var ReportPath = Server.MapPath("~/myreport.rdlc");
LocalReport localReport = new LocalReport();
localReport.ReportPath = ReportPath ;
ReportDataSource reportDataSource = new ReportDataSource("data", getReportData());
localReport.DataSources.Add(reportDataSource);
renderedBytes = localReport.Render(
reportType,
deviceInfo,
out mimeType,
out encoding,
out fileNameExtension,
out streams,
out warnings);
return File(renderedBytes, mimeType);
}
public static List<vwReport> getStudentClasses(string pYear)
{
return (from a in _dcSC.vwReport
where a.Year == pYear
orderby a.Period
select a).ToList();
}
public class vwReport {
[Required]
[MaxLength(50)]
[DisplayName("LName")]
public string LName { get; set; }
[MaxLength(50)]
[DisplayName("FName")]
public string FName { get; set; }
[MaxLength(50)]
[DisplayName("MName")]
public string MName { get; set; }
[Required]
[DisplayName("Id")]
public int Id { get; set; }
[Required]
[MaxLength(10)]
[DisplayName("Period")]
public string Period { get; set; }
[Required]
[MaxLength(4)]
[DisplayName("Year")]
public string Year { get; set; }
[MaxLength(50)]
[DisplayName("CNo")]
public string CNo { get; set; }
[Required]
[MaxLength(50)]
[DisplayName("Name")]
public string Name { get; set; }
[MaxLength(50)]
[DisplayName("Desc")]
public string Desc { get; set; }
[Required]
[DisplayName("M")]
public bool M { get; set; }
[Required]
[DisplayName("T")]
public bool T { get; set; }
[Required]
[DisplayName("W")]
public bool W { get; set; }
[Required]
[DisplayName("H")]
public bool H { get; set; }
[Required]
[DisplayName("F")]
public bool F { get; set; }
[Required]
[DisplayName("S")]
public bool S { get; set; }
[Required]
[DisplayName("N")]
public bool N { get; set; }
[MaxLength(10)]
[DisplayName("Type")]
public string Type { get; set; }
You need a foreach loop in your view class, and the Model type should be List<yourEntityClass>
This is not correct. There is no View, the OP is running a report, exporting it to PDF and returing the file. There is no attached view in such a scenario since the output of the action isn't markup, but a binary (pdf) file.
Check the reportDataSource while debugging to see if any data is in there, also check the rendered bytes.
alex_brambil...
Participant
773 Points
280 Posts
MVC 4 embedded rdlc report shows only 1st record
Nov 25, 2012 12:11 AM|LINK
Having a problem with an embedded rdlc report in an mvc 4 app. Finally got it working, but it's only showing the 1st record. The report uses a sql server view and I've verified that the List<> is passing multiple records, and I have no grouping in the report. Here's the code...
public ActionResult Report()
{
var ReportPath = Server.MapPath("~/myreport.rdlc");
LocalReport localReport = new LocalReport();
localReport.ReportPath = ReportPath ;
ReportDataSource reportDataSource = new ReportDataSource("data", getReportData());
localReport.DataSources.Add(reportDataSource);
string reportType = "PDF";
string mimeType;
string encoding;
string fileNameExtension;
string deviceInfo =
"<DeviceInfo>" +
" <OutputFormat>PDF</OutputFormat>" +
" <PageWidth>8.5in</PageWidth>" +
" <PageHeight>11in</PageHeight>" +
"</DeviceInfo>";
Warning[] warnings;
string[] streams;
byte[] renderedBytes;
renderedBytes = localReport.Render(
reportType,
deviceInfo,
out mimeType,
out encoding,
out fileNameExtension,
out streams,
out warnings);
return File(renderedBytes, mimeType);
}
public static List<vwReport> getStudentClasses(string pYear)
{
return (from a in _dcSC.vwReport
where a.Year == pYear
orderby a.Period
select a).ToList();
}
public class vwReport {
[Required]
[MaxLength(50)]
[DisplayName("LName")]
public string LName { get; set; }
[MaxLength(50)]
[DisplayName("FName")]
public string FName { get; set; }
[MaxLength(50)]
[DisplayName("MName")]
public string MName { get; set; }
[Required]
[DisplayName("Id")]
public int Id { get; set; }
[Required]
[MaxLength(10)]
[DisplayName("Period")]
public string Period { get; set; }
[Required]
[MaxLength(4)]
[DisplayName("Year")]
public string Year { get; set; }
[MaxLength(50)]
[DisplayName("CNo")]
public string CNo { get; set; }
[Required]
[MaxLength(50)]
[DisplayName("Name")]
public string Name { get; set; }
[MaxLength(50)]
[DisplayName("Desc")]
public string Desc { get; set; }
[Required]
[DisplayName("M")]
public bool M { get; set; }
[Required]
[DisplayName("T")]
public bool T { get; set; }
[Required]
[DisplayName("W")]
public bool W { get; set; }
[Required]
[DisplayName("H")]
public bool H { get; set; }
[Required]
[DisplayName("F")]
public bool F { get; set; }
[Required]
[DisplayName("S")]
public bool S { get; set; }
[Required]
[DisplayName("N")]
public bool N { get; set; }
[MaxLength(10)]
[DisplayName("Type")]
public string Type { get; set; }
}
eric2820
Contributor
2777 Points
1161 Posts
Re: MVC 4 embedded rdlc report shows only 1st record
Nov 25, 2012 12:41 AM|LINK
You need a foreach loop in your view class, and the Model type should be List<yourEntityClass>
http://www.my-msi.net/Admin
blog
If a post helps you, please mark it as Ansered, thank-you.
CodeHobo
All-Star
18647 Points
2647 Posts
Re: MVC 4 embedded rdlc report shows only 1st record
Nov 25, 2012 01:59 AM|LINK
This is not correct. There is no View, the OP is running a report, exporting it to PDF and returing the file. There is no attached view in such a scenario since the output of the action isn't markup, but a binary (pdf) file.
Check the reportDataSource while debugging to see if any data is in there, also check the rendered bytes.
Blog | Twitter : @Hattan