简体   繁体   English

在razor应用程序中的Crystal报表中查看对象列表

[英]View a list of objects in a crystal report within razor application

i have an asp.net mvc4 application with Razor, in which i 'd like to add a report Crystal Reports . 我有一个带有Razor的asp.net mvc4应用程序,我想在其中添加报表Crystal Reports So i create a folder AspxPages and i added an Aspx view. 因此,我创建了一个文件夹AspxPages并添加了一个Aspx视图。 Besides, i have in my models the class Result that i'd like to view a List<Result> like this: 此外,我在模型中有想要查看List<Result>类,如下所示:

List<Element> elem_list = notre_chef.Get_ListElement_By_Project(id_project);
List<Result> model = new List<Result>();
foreach (Element e in elem_list) 
{ 
   Result _r = new Result(e.Id_element);
   model.Add(_r);
}
string strReportName;
string rapportName;

strReportName = "Current.rpt";
rapportName = "Resultat Actuel du test";

ReportDocument rd = new ReportDocument();
// the Rapport path "Rpts/strReportName"

string strRptPath = 
    System.Web.HttpContext.Current.Server.MapPath("~/") + "Rpts//" 
        + strReportName;

rd.Load(strRptPath);
foreach (Result res in model)
{
    rd.SetParameterValue("category", res.Catégorie);
    rd.SetParameterValue("sf", res.Sous_fonctionnalité);
    rd.SetParameterValue("concept", res.Concept);
    rd.SetParameterValue("expert", res.Expert);
    rd.SetParameterValue("property", res.Propriétés);
    rd.SetParameterValue("f", res.Fonction);
    rd.SetParameterValue("avis", res.Avis);
    rd.SetParameterValue("justification", res.Justification);
    if (final == 0)
    {
       rd.SetParameterValue("titre", "Resultat actuel du test");
    }
    else
    {
        rd.SetParameterValue("titre", "Resultat final du test");
    }
}
rd.ExportToHttpResponse(ExportFormatType.PortableDocFormat,
    System.Web.HttpContext.Current.Response, false, rapportName);

return RedirectToAction("Display_Chef_Attempt", new{id_project = id_project});

In the report, I added the required fields. 在报告中,我添加了必填字段。 My problem is that only the last object Result in the list is shown in the report not all the list in different pages. 我的问题是报告中仅显示列表中的最后一个对象Result ,而不是在不同页面中显示所有列表。

So what is the problem? 那是什么问题呢? How can I fix it? 我该如何解决?

like bump sais you are trying to populate your paramenters with data, and of course the report will use just the last record. 就像凹凸塞子一样,您正在尝试使用数据填充参数,当然报表将仅使用最后一条记录。

what you are looking for is to set the datasource of the report document that should be something like this: 您正在寻找的是设置报告文档的数据源,该数据源应如下所示:

rd.SetDataSource(model);

Here you have a complete sample how to pass a generic collection to crystal. 在这里,您有一个完整的示例如何将通用集合传递给Crystal。 Crystal Report with generic Collection , this article should help you. 具有通用Collection的Crystal Report ,本文将为您提供帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM