or
@Html.Hidden("Report", Url.Action("Reports"))
<
script
id
=
"OHSTemplate"
type
=
"text/html"
>
<
tr
>
<
td
class
=
"formno"
>${formNo}</
td
>
<
td
class
=
"name"
>${ name }</
td
>
<
td
class
=
"online"
>-</
td
>
<
td
data-bind
=
"click: $parent.PrintCurrent.bind($data, fileName)"
class
=
"print"
></
td
>
</
tr
>
</
script
>
PrintCurrent: function (file) {
var Url, d;
Url = $('#Report').val();
d = { fileName: file };
$.ajaxSettings.traditional = true;
$.ajax({
type: "GET",
url: Url,
data: d,
contentType: "application/json;",
dataType: "json",
success: function (response) {
//response will give success or failure text (response.Result)
}
});
}
public class Results
{
string result;
public Results()
{
}
public string Result
{
get
{
return this.result;
}
set
{
this.result = value;
}
}
}
public JsonResult Reports(string fileName)
{
if(fileName != null)
{
Results results = new Results();
List<
Report
> reports = new List<
Report
>();
//Add each Telerik report you have that you'll be searching through
Report r = new Report();
r = (from c in reports
where c.Name == fileName
select c).FirstOrDefault();
//Configure Printer Settings
System.Drawing.Printing.PrinterSettings printerSettings = new System.Drawing.Printing.PrinterSettings();
if (printerSettings.CanDuplex)
{
printerSettings.Duplex = System.Drawing.Printing.Duplex.Default;
}
printerSettings.DefaultPageSettings.Color = false;
//Initialize ReportProcessor
Telerik.Reporting.Processing.ReportProcessor rp = new Telerik.Reporting.Processing.ReportProcessor();
//Print Report
try
{
rp.PrintReport(r, printerSettings);
results.Result = "Print Successful";
}
catch (Exception e)
{
results.Result = "Failed to print report because: " + e.InnerException;
}
return Json(results, JsonRequestBehavior.AllowGet);
}
return null;
}