Witam. Jestem totalnie nieobeznany z C# (ale zamierzam się go wreszcie nauczyć). Aktualnie dostałem projekt robiony przez jakiegoś studenta. Jest to aplikacja webowa (mniejsza o to dla kogo robiona), która na jednej stronie ma raporty w formie tabelki. Chciałbym stworzyć z tego plik pdf, a dokładniej dodać button, który jednym kliknięciem zapisze stronkę jako pdf. W założeniu powinienem użyć pdfsharp. Nie mam tylko pojęcia jak dodać kod w C# do tego buttona.
kod Index.cshtml:
@model HairdressingSalon.Web.ViewModels.ReportViewModel
@{
ViewBag.Title = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
ViewBag.IsAdminOrManager = User.IsInRole("Admin") || User.IsInRole("Manager");
}
<script type="text/javascript">
$(document).ready(function () {
function getLastDate() {
var date = new Date();
date.setMonth(date.getMonth() + 1, 0);
return date;
}
function getFirstDate() {
var date = new Date();
date.setMonth(date.getMonth(), 1);
return date;
}
var isAdminOrManager = "@ViewBag.IsAdminOrManager";
if (isAdminOrManager == "True") {
$('#mainTable').tablesorter(
{
sortList: [[0, 1]],
headers: {
4: {
sorter: false
},
5: {
sorter: false
},
7: {
sorter: false
}
}
});
} else {
$('#mainTable').tablesorter(
{
sortList: [[0, 1]],
headers: {
4: {
sorter: false
},
3: {
sorter: false
}
}
});
}
$('#printpage').click(function () {
print();
});
//--------------------------------------------------------------------
$('#print_as_pdf').click(function () {
Zapiszpdf(); // tutaj chcę wywołać funkcję tworzącą pdf.
});
//--------------------------------------------------------------------
$('.date_picker_empty,.date_picker_filled').click(function () {
if ($(this).val().length != 0)
$(this).attr("class", "date_picker_filled");
else
$(this).attr("class", "date_picker_empty");
});
$(".date_picker_empty,.date_picker_filled").datepicker({
dateFormat: "yy-mm-dd",
showAnim: "drop",
onSelect: function () {
if ($(this).val().length != 0)
$(this).attr("class", "date_picker_filled");
else
$(this).attr("class", "date_picker_empty");
}
});
$(".date_picker_empty,.date_picker_filled").datepicker($.datepicker.regional["pl"]);
var fromDate = "@ViewBag.StartDate" != '' ? "@ViewBag.StartDate" : getFirstDate();
var toDate = "@ViewBag.EndDate" != '' ? "@ViewBag.EndDate" : getLastDate();
$("[name='from']").datepicker('setDate', fromDate);
$("[name='to']").datepicker('setDate', toDate);
});
</script>
(...)
Jeśli ktoś mógłby mi w tym pomóc byłbym bardzo wdzięczny. A może istnieje jakaś inna, prostsza metoda stworzenia pdfa?