RDLC Report in ASP.Net MVC Razor/.Aspx

This article explains RDLC reports in MVC razor or .aspx.

Step 1: Create new folder as Report or other.

Step 2: If you have used a .cshtml page (Razor) then you also need to add a .Aspx page inside the folder (Report) as in above.

Step 3:
.cshtml is where you need to show the report; add the following code:

<div id="autoUpdate" style="display: none; overflow-y: auto" class="SlideContainer">

    <table width="100%" height="100%">











        <tr><td><iframe id="myReport" width="100%" height="800px"></iframe></td></tr>



And add a JavaScript code to the page:

$(window).load(function () {

    document.getElementById("myReport").src = "../../Report/CommonrdlcReport.aspx?ReportID=" + firstDropVal + "";



In the JavaScript code above a parameter; if you don't want t then just remove this: + firstDropVal + ""; and a name ie.DEMO in the query string.

Step 4: Now add a DataSet from Add New item from Visual Studio and add it under the Report folder or root folder.

Step 5: Now create a procedure in SQL and in the Dataset UI right-click and select "Add TableAdopter" and use an existing procedure so you can access it in the RDLC further.

Step 6: Now create a RDLC folder in the root and add Report.rdlc from both. You can select whichever you want. Then to open the RDLC go to Dataset, add Datasets and select the Data source. If you are doing this the first time then click on "New" and access the procedure or table that you created. Then from the Available datasets select a record and click "OK".

Step 7: If you want to show a report then do that like this:

Show report

Add a table to the RDLC and create a parent group and right-click on the parent group field then insert a column add inside the group right-click and add another column field then right-click on the second field then select TextBox properties then select Visibility then select Hide and below select the Parent group field so you can see like above.

Step 8: Now go to the Report folder and select the .aspx page then go to the code behind or just double click. Now for the Page Load write the following code:

if (!Page.IsPostBack)


        if (Request.QueryString["ReportID"] !=null)


        SqlCommand cmdLatest = OpenConnection("SlideSearchDetails");

        cmdLatest.Parameters.Add("@UserAlias", reportID.Trim());

        cmdLatest.Parameters.Add("@StartDate", StartDate.Trim());

        cmdLatest.Parameters.Add("@EndDate", EndDate.Trim());

        DataSet dt = GetDataSet(cmdLatest);


        ReportViewer1.LocalReport.ReportPath = "RDLC/rptSearchKeyWord.rdlc";


        ReportViewer1.LocalReport.DataSources.Add(new Microsoft.Reporting.WebForms.ReportDataSource("SlideSearchkey", dt.Tables[0]));


Outside of the page load make a function as in the following:

public SqlCommand OpenConnection(string strSpName)


    SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["slideConnectionString"].ConnectionString);

    SqlCommand cmd = new SqlCommand();

    cmd.CommandText = strSpName;

    cmd.Connection = con;

    cmd.CommandType = CommandType.StoredProcedure;


    return cmd;

public DataSet GetDataSet(SqlCommand cmd)


    SqlDataAdapter da = new SqlDataAdapter(cmd);

    DataSet ds = new DataSet();


    return ds;


If you are using a parameter then you need to use the following code.

Here I am ing an image as a parameter.

string DomainURL = Request.Url.GetLeftPart(UriPartial.Authority);


List<ReportParameter> reportParameter = null;

reportParameter = new List<ReportParameter>(1);

reportParameter.Add(new ReportParameter("SlideURL", DomainURL));

ReportViewer1.LocalReport.ReportPath = "RDLC/rptReport1.rdlc";

ReportViewer1.LocalReport.EnableExternalImages = true;



ReportViewer1.LocalReport.DataSources.Add(new Microsoft.Reporting.WebForms.ReportDataSource("DataSet1", dt.Tables[0]));

If you use an image in RDLC then add the image and select properties then select the image source as External and below that write an expression for the field you need to show the image in as in the following:
=Parameters!SlideURL.Value & Fields!ThumnailPath.Value