2014-02-18 2 views
0

Я очень новичок в Asp.Net MVC4. У меня есть отчет rdlc, и мне нужно добавить этот отчет на моей индексной странице. Но я googled много, они предложили как файл PDF или файл изображения. Мне нужно отобразить отчет на самой странице. Как это можно сделать?Показать отчет Rdlc на веб-странице в Asp.Net Mvc4

Спасибо,

Таня

ответ

0

Вы можете создать страницу ASPX с отчетом, а затем встроить отчет в <iframe /> на ваш взгляд MVC, или вы можете попробовать с помощью этого метода, который возвращает пар непосредственно на ответ:

private void RenderReport() { 

    LocalReport localReport = new LocalReport(); 

    localReport.ReportPath = Server.MapPath("~/YourReportName.rdlc"); 

    // Add your data source 
    ReportDataSource reportDataSource = new ReportDataSource("YourCollection", yourCollection); 

    localReport.DataSources.Add(reportDataSource); 

    string reportType = "PDF"; 
    string mimeType; 
    string encoding; 
    string fileNameExtension; 

    //The DeviceInfo settings should be changed based on the reportType 
    string deviceInfo = 
     "<DeviceInfo>" + 
     " <OutputFormat>PDF</OutputFormat>" + 
     " <PageWidth>8.5in</PageWidth>" + 
     " <PageHeight>11in</PageHeight>" + 
     " <MarginTop>0.5in</MarginTop>" + 
     " <MarginLeft>1in</MarginLeft>" + 
     " <MarginRight>1in</MarginRight>" + 
     " <MarginBottom>0.5in</MarginBottom>" + 
     "</DeviceInfo>"; 

    Warning[] warnings; 
    string[] streams; 
    byte[] renderedBytes; 

    //Render 
    renderedBytes = localReport.Render(
     reportType, 
     deviceInfo, 
     out mimeType, 
     out encoding, 
     out fileNameExtension, 
     out streams, 
     out warnings); 

    //Write to the outputstream 
    //Set content-disposition to "attachment" so that user is prompted to take an action 
    //on the file (open or save) 

    Response.Clear(); 
    Response.ContentType = mimeType; 
    Response.AddHeader("content-disposition", "attachment; filename=foo." + fileNameExtension); 
    Response.BinaryWrite(renderedBytes); 
    Response.End(); 
} 

вы, возможно, потребуется изменить ReportType к WATH вам нужно, и не забудьте изменить DeviceInfo соответственно к нему. Вы можете найти информацию here.

Надеюсь, это поможет вам.

+0

Есть ли какие-либо варианты там кроме PDF. Я дал MHTML, но это была ошибка: «Формат параметра - исключение вне диапазона». – Tanya

1

Это 1 год назад, но многие люди могут по-прежнему нажимать эту страницу для решения, поэтому я решил ответить на этот вопрос.

-> Вы считали использовать ReportViewer для отображения отчета rdlc на своем веб-сайте?

1) Создайте страницу Aspx. Добавьте «ScriptManager» на эту страницу из опции «AjaxExtension». 2) Добавьте «ReportViewer» на эту страницу из опции «Отчет». 3) И рассмотрите следующий код для назначения источника данных в кодовом списке этой страницы aspx.

string ID = Request.QueryString["ID"];     
List<Obj1> List1 = new List<Obj1>(); 
List<Obj2> List2 = new List<Obj2>(); 
List<Obj3> List3 = new List<Obj3>(); 

    using (var db = new 'use ur edmx connectionstring name') 
    {         
     List1 = db.'urTableName1'.Where(x => x.ID == ID).ToList(); 
     List2 = db.'urTableName2'.Where(y => y.ID == ID).ToList(); 
     List3 = db.'urTableName3'.Where(z => z.ID == ID).ToList();      
    } 

    rptVWSmartBOM.LocalReport.DataSources.Clear(); 

    ReportDataSource rd1 = new ReportDataSource("Your DataTable name used in DataSet", List1); 
    ReportDataSource rd2 = new ReportDataSource("Your DataTable name used in DataSet", List1); 
    ReportDataSource rd3 = new ReportDataSource("Your DataTable name used in DataSet", List1); 
    ReportViewer1.LocalReport.DataSources.Add(rd1); 
    ReportViewer1.LocalReport.DataSources.Add(rd2); 
    ReportViewer1.LocalReport.DataSources.Add(rd3);         
    ReportViewer1.LocalReport.ReportPath = "xyz.rdlc"; 

    ReportViewer1.LocalReport.Refresh(); 
Смежные вопросы