Hi,
I tried making report generate with the ID as parameter but the result return blank value, when I use same code without the parameter the report get the correct value. Any help could be appreciate.
I'm sure sir the parameter passing not nulls value and the record on database get correct value when I tried to generate it.
The View
@using Klinik_Apps.Models
@model RawatModel
@{
ViewBag.Title = "Report Pasien";
Layout = "~/Views/Shared/AdminDashboard/_Layout.cshtml";
}
<div align="left">
<table>
<tr>
<td>
<input type="text" asp-for="ID_Rawat" name="ID_Rawat" class="form-control" placeholder="Enter ID Rawat"/>
</td>
<td>
<form asp-action="FilterReportRawatByID" asp-controller="ReportRawat" method="post">
<button type="submit" class="btn btn-success btn-sm"> Export To Pdf</button>
</form>
</td>
</tr>
</table>
</div>
The Controller.cs
[HttpPost]
public IActionResult FilterReportRawatByID(int ID_Rawat)
{
DataTable dt = new DataTable();
using (SqlConnection con = new SqlConnection(this._configuration.GetConnectionString("Db_Klinik")))
{
using (SqlCommand cmd = new SqlCommand())
{
con.Open();
cmd.Connection = con;
cmd.CommandType = System.Data.CommandType.Text;
cmd.CommandText = "Select * From View_Report_Join_Rawat_Pasien Where ID_Rawat=@ID_Rawat";
cmd.Parameters.AddWithValue("@ID_Rawat", ID_Rawat);
using (SqlDataAdapter adap = new SqlDataAdapter(cmd))
{
adap.Fill(dt);
}
con.Close();
}
}
string mimtype = "";
int extension = 1;
var path = $"{this._webHostEnvirnoment.WebRootPath}\\Reporting\\ReportRawatFilterByID.rdlc";
LocalReport localReport = new LocalReport(path);
localReport.AddDataSource("DataSetRawatFilterByID", dt);
Dictionary<string, string> parameters = new Dictionary<string, string>();
parameters.Add("rp1", "Laporan Rawat Data Pasien");
var result = localReport.Execute(RenderType.Pdf, extension, parameters, mimtype);
return File(result.MainStream, "application/pdf");
}