This is a migrated thread and some comments may be shown as answers.

Programatically setting EntityDataSource

1 Answer 37 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Ken
Top achievements
Rank 1
Ken asked on 29 Apr 2013, 01:58 PM
Hi, recently started using the free trial of Telerik Reporting in my MVC project. So what I do is, on the client side, when a button is pressed, it sends down an ID to the controller which calls GetReport to get data matching the ID, and then return a report back to the client. However, I keep getting this error <ExceptionMessage>Invalid value of report parameter 'id'.</ExceptionMessage>.

What am I doing wrong? I think I'm doing this correctly going by the resources: http://www.telerik.com/help/reporting/entitydatasource-connecting-to-entity-data-model.html

NB: int _stuffId is never null, it does have a value when I debugged the app.

// ReportRepo.cs
 
public Report GetReportData(int _id)
{
    return m_context.Stuff.SingleOrDefault(c => c.StuffId == _id);
}
 
// controller
public HttpResponseMessage GetReport(int _stuffId)
{
    try
    {
        EntityDataSource entityDataSource = new EntityDataSource();
        entityDataSource.ObjectContext = typeof(ReportRepo);
        entityDataSource.ObjectContextMember = "GetReportData";
        entityDataSource.Parameters.Add("_id", typeof(int), _stuffId);
 
        Report1 report1 = new Report1();
        report1.DataSource = entityDataSource;
 
        ReportProcessor reportProcessor = new ReportProcessor();
        InstanceReportSource instanceReportSource = new InstanceReportSource();
        instanceReportSource.ReportDocument = report1;
        RenderingResult result = reportProcessor.RenderReport("PDF", instanceReportSource, null);
 
        HttpResponseMessage response = new HttpResponseMessage(HttpStatusCode.OK);
        var stream = new MemoryStream(result.DocumentBytes);
        response.Content = new StreamContent(stream);
        response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");
        response.Content.Headers.ContentDisposition = new System.Net.Http.Headers.ContentDispositionHeaderValue("attachment");
        response.Content.Headers.ContentDisposition.FileName = result.DocumentName + "." + result.Extension;
 
        return response;
    }
}

1 Answer, 1 is accepted

Sort by
0
Ken
Top achievements
Rank 1
answered on 29 Apr 2013, 02:10 PM
Solution: Removed property binding in the report design properties.
Tags
General Discussions
Asked by
Ken
Top achievements
Rank 1
Answers by
Ken
Top achievements
Rank 1
Share this question
or