Tôi khá mới với ASP.Net MVC. Tôi có một yêu cầu để hiển thị một báo cáo dựa trên RDLC trong MVC.Làm thế nào tôi có thể sử dụng báo cáo RDLC với điều khiển ReportViewer trong ASP.Net MVC?
Về cơ bản yêu cầu của tôi cũng như những gì tôi đã làm là: -
Tôi có một ReportController kế thừa APIController, trong đó có một phương thức trả về một DataSet. Số liệu này đang được gửi đến tệp RDLC.
Đối với điều này, tôi đã làm như sau, nhưng không thể làm cho báo cáo hoạt động.
Tôi đã tạo ra một lớp mô hình tên ReportParameter như sau:
public class ReportParameter
{
public DateTime DateFrom { get; set; }
public DateTime DateTo { get; set; }
}
Tôi có ReportViewController điều khiển sau:
public class ReportViewController : Controller
{
static readonly ReportController ctrl = new ReportController();
public ActionResult GenerateReport()
{
return View();
}
[HttpPost]
public ActionResult GenerateReport(ReportParameterSalesOrder param)
{
if (ModelState.IsValid)
{
Helpers.DataLayer dl = new Helpers.DataLayer();
if (param.DateFrom != null)
{
DateTime DateFrom = Convert.ToDateTime(param.DateFrom);
DateTime DateTo = Convert.ToDateTime(param.DateTo);
string fdate = DateFrom.ToString("yyyy/MM/dd");
string tdate = DateTo.ToString("yyyy/MM/dd");
Session["ReportSales"] = ctrl.ReportSales(param);
}
return Redirect(Url.Action("ViewReport", "ReportView"));
}
return View();
}
public ActionResult ViewReport()
{
return View();
}
}
Tôi có một API điều khiển ReportController mà đối tượng đã được tạo ra ở trên ReportViewerController để tạo ra một DataSet và điền vào báo cáo RDLC. Bộ điều khiển API là:
public class ReportController : ApiController
{
static readonly IReportRepository repository = new ReportRepository();
[ActionName("ReportSales")]
public DataSet ReportSales(ReportParameterSalesOrder paramSO)
{
DataSet item = repository.ReportSales(paramSO);
if (item == null)
{
throw new HttpResponseException(HttpStatusCode.NotFound);
}
return item;
}
}
Tôi có hai chế độ xem GenerateReport.aspx và ViewReport.aspx. Các GenerateReport.aspx được đưa ra dưới đây:
<table style="width: 40%;">
<tr>
<td class="style1">
<h3>
<asp:Label ID="Label1" runat="server" Text="From Date"></asp:Label></h3>
</td>
<td>
<%[email protected](a=> a.DateFrom, new{id="startDate",style="width:250px;"}) %>
<%[email protected](a => a.DateFrom)%>
</td>
</tr>
<tr>
<td class="style1">
<h3>
<asp:Label ID="Label2" runat="server" Text="To Date"></asp:Label></h3>
</td>
<td>
<%[email protected](a => a.DateTo, new { id = "ToDate", style = "width: 250px;" })%>
<%[email protected](a => a.DateTo)%>
</td>
</tr>
<tr>
<td class="style1">
</td>
<td>
</td>
</tr>
<tr>
<td class="style1">
</td>
<td>
<input id="btnsearch" class="button" type="submit" value="Show" />
</td>
</tr>
</table>
các ViewReport.aspx được đưa ra dưới đây:
<center style="width: 974px">
<iframe id="myReport" width="100%" height="450px" src="ReportViewer.aspx">
</iframe></center>
Tôi đã thêm một Dataset.xsd, một tập tin rdlc và một trang aspx để thêm các tập tin rdlc .
Nhưng tôi không thể làm cho nó hoạt động. Làm cách nào để hiển thị báo cáo hoặc làm cách nào để điền tập dữ liệu mà tôi nhận được từ Bộ điều khiển vào báo cáo?
'ViewReport.aspx' được sử dụng trong' iframe' sẽ cần phải là một biểu mẫu web thời trang cũ có mã phía sau - ví dụ: đặt DataSet trong mã phía sau 'ViewReport.aspx.cs'. Những gì bạn có thể làm là truyền dữ liệu từ Bộ điều khiển MVC qua biến 'Session []'? – StuartLC
ViewReport.aspx không có mã phía sau tệp. Bạn có thể giải thích thêm một chút không? – Nubicus