This question is locked. New answers and comments are not allowed.
HI!
I am supposed to generate the report (from reporting services 2005) using MVC as the parameter screen.
As i found from my earlier researches that MVC doesn't support Report Viewer Controller, I am looking for other ways to present the data of the report. I can't use .ASPX pages in my project to accommodate the Report viewer Controller.
Is it feasible to use MVC to generate the images or .pdf files as the output of the report which i call using MVC pages as the parameter screen?
Please suggest.
I am supposed to generate the report (from reporting services 2005) using MVC as the parameter screen.
As i found from my earlier researches that MVC doesn't support Report Viewer Controller, I am looking for other ways to present the data of the report. I can't use .ASPX pages in my project to accommodate the Report viewer Controller.
Is it feasible to use MVC to generate the images or .pdf files as the output of the report which i call using MVC pages as the parameter screen?
Please suggest.
13 Answers, 1 is accepted
0
Hi,
Atanas Korchev
the Telerik team
This questions does not seem related to Telerik Extensions for ASP.NET MVC. However we can probably give you some guidelines.
Since the report viewer control requires ASPX page you can either add a single ASPX page to your MVC application or use an ASCX partial view which can be rendered inside any razor view using Html.RenderPartial.
Atanas Korchev
the Telerik team
Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
0

Dadv
Top achievements
Rank 1
answered on 22 Feb 2012, 04:54 PM
Hi,
In a project i use the RS web service to generate pdf file in an MVC project.
Now create a Custom toolbar like here : http://demos.telerik.com/aspnet-mvc/grid/customcommand
This is an example, change it for your own project
Regards,
In a project i use the RS web service to generate pdf file in an MVC project.
- First you have to add a web reference to "/ReportServer/ReportExecution2005.asmx" and "/ReportServer/ReportService2005.asmx"
- Create a Action that call the services like this :
private
byte
[] CallReportingService(
string
reportName,
string
fileFormat, Dictionary<
string
,
string
> values)
{
Projibat.Site.ReportService2005.ReportingService2005 rs =
new
ReportService2005.ReportingService2005();
Projibat.Site.ReportExecution2005.ReportExecutionService rsExec =
new
ReportExecution2005.ReportExecutionService();
rs.Credentials = System.Net.CredentialCache.DefaultCredentials;
rsExec.Credentials = System.Net.CredentialCache.DefaultCredentials;
rs.Url = Settings.Default.ReportingService2005;
rsExec.Url = Settings.Default.ReportExecutionService;
string
historyID =
null
;
string
deviceInfo =
null
;
Byte[] results;
string
encoding = String.Empty;
string
mimeType = String.Empty;
string
extension = String.Empty;
ReportExecution2005.Warning[] warnings =
null
;
string
[] streamIDs =
null
;
string
_historyID =
null
;
bool
_forRendering =
false
;
ReportService2005.ParameterValue[] _values =
null
;
ReportService2005.DataSourceCredentials[] _credentials =
null
;
ReportService2005.ReportParameter[] _parameters =
null
;
_parameters = rs.GetReportParameters(reportName, _historyID, _forRendering, _values, _credentials);
ReportExecution2005.ExecutionInfo ei = rsExec.LoadReport(reportName, historyID);
List<ReportExecution2005.ParameterValue> parameters =
new
List<ReportExecution2005.ParameterValue>();
foreach
(var param
in
_parameters)
{
if
(values !=
null
&& values.ContainsKey(param.Name))
{
parameters.Add(
new
ReportExecution2005.ParameterValue
{
Label = param.Prompt,
Name = param.Name,
Value = values[param.Name]
});
}
}
rsExec.SetExecutionParameters(parameters.ToArray(), System.Globalization.CultureInfo.CurrentCulture.Name);
results = rsExec.Render(fileFormat, deviceInfo,
out
extension,
out
mimeType,
out
encoding,
out
warnings,
out
streamIDs);
return
results;
}
public ActionResult ExportPdf(int page, string orderBy, string filter)
{
var dico = new Dictionary<string, string>();
dico["filter"] = filter;
dico["orderBy"] = orderBy;dico["page"] = page.ToString();
var results = CallReportingService(@"/Contract", "PDF", dico);
return File(results, System.Net.Mime.MediaTypeNames.Application.Pdf, "Contrat.pdf");
}
Now create a Custom toolbar like here : http://demos.telerik.com/aspnet-mvc/grid/customcommand
.ToolBar(commands => commands
.Custom()
.HtmlAttributes(new { id = "export" })
.Text("Export to pdf")
.Action("ExportPdf", "Grid", new { page = 1, orderBy = "~", filter =
"~" }))This is an example, change it for your own project
Regards,
0

Howard
Top achievements
Rank 1
answered on 23 Feb 2012, 11:22 PM
Hi Dadv,
Thank you for the reply,
What i couldn't get is "First you have to add a web reference to "/ReportServer/ReportExecution2005.asmx" and "/ReportServer/ReportService2005.asmx"
I just couldn't get this web reference while trying to add from "Add Reference" and the options available there.
Also, some of our clients use SSRS 2008R2.
Will this web reference work for them also or i need to add other references too.
Please help!!
Thank you for the reply,
What i couldn't get is "First you have to add a web reference to "/ReportServer/ReportExecution2005.asmx" and "/ReportServer/ReportService2005.asmx"
I just couldn't get this web reference while trying to add from "Add Reference" and the options available there.
Also, some of our clients use SSRS 2008R2.
Will this web reference work for them also or i need to add other references too.
Please help!!
0

Dadv
Top achievements
Rank 1
answered on 24 Feb 2012, 10:02 AM
Hi,
you have to activate the web service before in configuration panel (http://msdn.microsoft.com/en-us/library/bb630447.aspx )
then add a web reference (not a service reference) to :
http://[address to the server]/[server name (reportserver by default)]/ReportExecution2005.asmx?wdsl
and
http://[address to the server]/[server name (reportserver by default)]/ReportService2005.asmx?wdsl
I'm using SSRS 2008 and it use the same web service reference, i don't know for the R2 version, but i think it's similar.
(Google tell me that the ref name should be reportingService2010 but it seems to be a simple merge of the 2 above).
Regards,
you have to activate the web service before in configuration panel (http://msdn.microsoft.com/en-us/library/bb630447.aspx )
then add a web reference (not a service reference) to :
http://[address to the server]/[server name (reportserver by default)]/ReportExecution2005.asmx?wdsl
and
http://[address to the server]/[server name (reportserver by default)]/ReportService2005.asmx?wdsl
I'm using SSRS 2008 and it use the same web service reference, i don't know for the R2 version, but i think it's similar.
(Google tell me that the ref name should be reportingService2010 but it seems to be a simple merge of the 2 above).
Regards,
0

saroj
Top achievements
Rank 1
answered on 29 Feb 2012, 04:35 AM
Hi Dadv,
Thank you again for the reply.
But a question please, what if i use only SSRS 2005 for creating the reports.
Does it work as you mentioned above?
Reports will be created in SSRS 2005 only but need to be deployed for SQL 2005, SQL 2008 or SQL 2008R2.
Any idea please?
Thank you again for the reply.
But a question please, what if i use only SSRS 2005 for creating the reports.
Does it work as you mentioned above?
Reports will be created in SSRS 2005 only but need to be deployed for SQL 2005, SQL 2008 or SQL 2008R2.
Any idea please?
0

Dadv
Top achievements
Rank 1
answered on 29 Feb 2012, 09:28 AM
Hi,
The Report Server Web Service only give access to the "logic" of SSRS.
by using it you can recover the raw result of the report from the format you want (PDF, HTML, XLS, etc... depend of you ssrs version), this service is versioned so it's the same implementation from any sql server database (backward compatibility).
The only thing you have to be aware is the report it self, because all version are not compatible, but if you make all in 2005 version all will work fine.
In my project i have 2 sql server versions (2008 and 2008 R2) i create my report on 2008 version and on release, i convert in 2008R2 version for sql server 2008 R2, my code didn't change.. only the xml format of the report change (remember, backward compatibility).
Same thing for the report builder (v1,v2 and v3).
Be careful to not open in the bad version a report or it will convert it automatically.
I'm not sure to have give a clear explanation... i resume ... you can create report on what you want , it will be convert but only in up version :
Created report on 2005 could be deployed on 2008 and 2008 R2
Created report on 2008 could be deployed on 2008 R2 - not in 2005(format is not the same and you could loose some part)
Tell me if you didn't understand :) my English is so poor...
Regards,
The Report Server Web Service only give access to the "logic" of SSRS.
by using it you can recover the raw result of the report from the format you want (PDF, HTML, XLS, etc... depend of you ssrs version), this service is versioned so it's the same implementation from any sql server database (backward compatibility).
The only thing you have to be aware is the report it self, because all version are not compatible, but if you make all in 2005 version all will work fine.
In my project i have 2 sql server versions (2008 and 2008 R2) i create my report on 2008 version and on release, i convert in 2008R2 version for sql server 2008 R2, my code didn't change.. only the xml format of the report change (remember, backward compatibility).
Same thing for the report builder (v1,v2 and v3).
Be careful to not open in the bad version a report or it will convert it automatically.
I'm not sure to have give a clear explanation... i resume ... you can create report on what you want , it will be convert but only in up version :
Created report on 2005 could be deployed on 2008 and 2008 R2
Created report on 2008 could be deployed on 2008 R2 - not in 2005(format is not the same and you could loose some part)
Tell me if you didn't understand :) my English is so poor...
Regards,
0

Howard
Top achievements
Rank 1
answered on 29 Feb 2012, 11:46 PM
Hi Dadv,
Also, i want to ask another issue, if i want to generate Report.aspx page using MVC rather than converting into .pdf or excel file, will it be possible?
More clearly, i want to display the report in the .ASPX page rather than export directly into .PDF or .xls format. The input will be on the MVC Razor page , output desired is Report_preview.ASPX page. If users want to export in other format, they can do it later as the Report from Reporting Services have those options.
Does this help you to suggest me the answer?
Thanks
Also, i want to ask another issue, if i want to generate Report.aspx page using MVC rather than converting into .pdf or excel file, will it be possible?
More clearly, i want to display the report in the .ASPX page rather than export directly into .PDF or .xls format. The input will be on the MVC Razor page , output desired is Report_preview.ASPX page. If users want to export in other format, they can do it later as the Report from Reporting Services have those options.
Does this help you to suggest me the answer?
Thanks
0

Dadv
Top achievements
Rank 1
answered on 01 Mar 2012, 10:05 AM
From what i know the ReportViewer didn't exist in MVC, but you can use a bypass with iframe.
Here my solution :
- First create a folder "Reports" in the site root (not in views).
- Create inside a aspx file name "GenericReport.aspx" in webform format (not mvc) without masterpage like this :
And the codebehind :
Add any logic you need inside.
This is a "generic" report viewer, if you call it in a iframe with querystring parameters, it will work like if it was natively in a aspx page.
Now the MVC part ...
- In the Views Folder create a "Report" folder
- Create a "Partial View" typed as "String" named ReportControl.acx (or ReportControl.cshtml in Razor) like this :
Now it's like an other PartialView, you just have to refer to it in an Action (don't forget to create a controller named "Report") :
That's all, it should work (for me it does).
Regards,
Here my solution :
- First create a folder "Reports" in the site root (not in views).
- Create inside a aspx file name "GenericReport.aspx" in webform format (not mvc) without masterpage like this :
<%@ Page Title="" Language="C#" AutoEventWireup="true" CodeBehind="GenericReport.aspx.cs"
Inherits="Projibat.Site.Reports.GenericReport" %>
<%@ Register Assembly="Microsoft.ReportViewer.WebForms, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
Namespace="Microsoft.Reporting.WebForms" TagPrefix="rsweb" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD AZXHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<
html
xmlns
=
"http://www.w3.org/1999/xhtml"
>
<
head
id
=
"Head1"
runat
=
"server"
>
<
title
></
title
>
</
head
>
<
body
>
<
form
id
=
"form1"
runat
=
"server"
>
<
div
>
<
asp:ScriptManager
ID
=
"ScriptManager1"
runat
=
"server"
>
</
asp:ScriptManager
>
<
rsweb:ReportViewer
ID
=
"ReportViewer1"
runat
=
"server"
Font-Names
=
"Verdana"
Font-Size
=
"8pt"
ProcessingMode
=
"Remote"
ShowParameterPrompts
=
"False"
Width
=
"100%"
Height
=
"100%"
AsyncRendering
=
"false"
ShowDocumentMapButton
=
"False"
ShowFindControls
=
"False"
SizeToReportContent
=
"True"
ShowRefreshButton
=
"True"
ExportContentDisposition
=
"AlwaysAttachment"
ShowBackButton
=
"False"
ToolBarItemHoverBackColor
=
"#D7DFF7"
ToolBarItemBorderColor
=
"#D7DFF7"
SplitterBackColor
=
"#D7DFF7"
>
<
ServerReport
/>
</
rsweb:ReportViewer
>
</
div
>
</
form
>
</
body
>
</
html
>
And the codebehind :
protected
void
Page_Load(
object
sender, EventArgs e)
{
if
(!
this
.Page.IsPostBack)
{
List<ReportParameter> parameters =
new
List<ReportParameter>();
foreach
(var key
in
this
.Page.Request.QueryString.AllKeys.Where(k => k !=
null
&& k.StartsWith(
"__"
)))
{
ReportParameter parameter =
new
ReportParameter();
parameter.Name = key.Substring(2);
parameter.Values.Add(
this
.Page.Request.QueryString[key]);
parameters.Add(parameter);
}
this
.ReportViewer1.ServerReport.ReportServerUrl =
new
Uri(
"[ReportUrl]"
);
if
(
this
.Page.Request.QueryString[
"ReportName"
] !=
null
)
this
.ReportViewer1.ServerReport.ReportPath =
"[DefaultReportName]"
;
this
.ReportViewer1.ServerReport.SetParameters(parameters);
}
}
Add any logic you need inside.
This is a "generic" report viewer, if you call it in a iframe with querystring parameters, it will work like if it was natively in a aspx page.
Now the MVC part ...
- In the Views Folder create a "Report" folder
- Create a "Partial View" typed as "String" named ReportControl.acx (or ReportControl.cshtml in Razor) like this :
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<
string
>" %>
<
iframe
width
=
"100%"
id
=
"iframeReport"
onload
=
"calcHeight();"
src="<%=Model %>" scrolling="no" frameborder="0" height="100px"></
iframe
>
<script language=
"JavaScript"
type=
"text/javascript"
>
function
calcHeight() {
//get the height of the page
var
height = document.getElementById(
'iframeReport'
).contentWindow.document.body.scrollHeight;
//change the iframe
height
document.getElementById(
'iframeReport'
).height = height + 20;
}
var
test =
'test'
;
</script>
Now it's like an other PartialView, you just have to refer to it in an Action (don't forget to create a controller named "Report") :
public
ActionResult ReportAction(
int
customerId)//Personalize the parameters for your logic
{
Dictionary<
string
,
object
> dic =
new
Dictionary<
string
,
object
>();
dic[
"CustomerId"
] = customerId; // Add all the parameters here
string
url = UrlReportBuilder(
"ReportName"
, dic);
return
PartialView(
"ReportControl"
, url);
}
private
string
UrlReportBuilder(
string
reportName, Dictionary<
string
,
object
> dic)
{
StringBuilder sb =
new
StringBuilder();
sb.AppendFormat(
"ReportName={0}"
, reportName);
foreach
(var item
in
dic)
{
sb.AppendFormat(
"&{0}={1}"
,
"__"
+ item.Key, item.Value);
}
return
Url.Content(
"/Reports/GenericReport.aspx?"
+ sb.ToString());
}
That's all, it should work (for me it does).
Regards,
0

Alexandra
Top achievements
Rank 1
answered on 01 Mar 2012, 04:42 PM
Thanks for post. It’s really informative stuff.
I really like to read.Hope to learn a lot and have a nice experience here! my best regards guys!
call center jobs in kanpur
call center jobs in lucknow
0

saroj
Top achievements
Rank 1
answered on 05 Mar 2012, 02:16 AM
HI Dadv,
Thank you for the repliy.
I am working on the instruction and the code you sent.
But i couple of issues i am facing here,
a. Error 19 'AusFleet.Web.Reports.GenericReport' does not contain a definition for 'ReportViewer1' and no extension method 'ReportViewer1' accepting a first argument of type 'AusFleet.Web.Reports.GenericReport' could be found (are you missing a using directive or an assembly reference?)
I am using the references as using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Microsoft.Reporting.WebForms;
I believe, i am missing something here.
Any idea please?
Thank you for the repliy.
I am working on the instruction and the code you sent.
But i couple of issues i am facing here,
a. Error 19 'AusFleet.Web.Reports.GenericReport' does not contain a definition for 'ReportViewer1' and no extension method 'ReportViewer1' accepting a first argument of type 'AusFleet.Web.Reports.GenericReport' could be found (are you missing a using directive or an assembly reference?)
I am using the references as using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Microsoft.Reporting.WebForms;
I believe, i am missing something here.
Any idea please?
0

Dadv
Top achievements
Rank 1
answered on 05 Mar 2012, 09:12 AM
Hi,
I think the best way to solve your problem is to drag and drop the reportviewer from the toolbar to the page, VS will add all the needed references ... normally ...
Don't forget to drag and drop the ScriptManager too.
Regards,
I think the best way to solve your problem is to drag and drop the reportviewer from the toolbar to the page, VS will add all the needed references ... normally ...
Don't forget to drag and drop the ScriptManager too.
Regards,
0

saroj
Top achievements
Rank 1
answered on 06 Mar 2012, 12:06 AM
Hi Dadv,
Thank you for the reply but still the same error is there.
Or the eoor is
Parser Error Message: 'GenericReport' is not allowed here because it does not extend class 'System.Web.UI.Page'.
Source Error:
Source File: /Reports/GenericReport.aspx Line: 1
Any idea please?
Thank you for the reply but still the same error is there.
Or the eoor is
Parser Error Message: 'GenericReport' is not allowed here because it does not extend class 'System.Web.UI.Page'.
Source Error:
|
Source File: /Reports/GenericReport.aspx Line: 1
Any idea please?
0

Dadv
Top achievements
Rank 1
answered on 06 Mar 2012, 09:46 AM
Ok do you create an ASPX.NET web form ? (not MVC) you need the code-behind with... (Add->new item-> Web/Web Form)
Don't forget to place the page out of the Views folder (or the route magic of mvc will take the query)
I had only copy/past the page_load method, not the entire page code :
Regards,
Don't forget to place the page out of the Views folder (or the route magic of mvc will take the query)
I had only copy/past the page_load method, not the entire page code :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Microsoft.Reporting.WebForms;
namespace Site.Reports
{
public partial class GenericReport : Page
{
protected
void
Page_Load(
object
sender, EventArgs e)
{
if
(!
this
.Page.IsPostBack)
{
List<ReportParameter> parameters =
new
List<ReportParameter>();
foreach
(var key
in
this
.Page.Request.QueryString.AllKeys.Where(k => k !=
null
&& k.StartsWith(
"__"
)))
{
ReportParameter parameter =
new
ReportParameter();
parameter.Name = key.Substring(2);
parameter.Values.Add(
this
.Page.Request.QueryString[key]);
parameters.Add(parameter);
}
this
.ReportViewer1.ServerReport.ReportServerUrl =
new
Uri(
"[ReportUrl]"
);
if
(
this
.Page.Request.QueryString[
"ReportName"
] !=
null
)
this
.ReportViewer1.ServerReport.ReportPath =
"[DefaultReportName]"
;
this
.ReportViewer1.ServerReport.SetParameters(parameters);
}
}
}
}
Regards,