I am trying to print output in asp.net mvc, but the codes I wrote do not work. Can you find a solution?
<a href="#" onclick="PrintFunction('#printdiv')" target="_blank" class="btn btn-warning">Yazdır</a>
<div id="printdiv">
<table class="table table-bordered" style="margin-left: 20%; width: 50%">
<tr>
<th>Stok Adı</th>
<th>Miktar</th>
<th>Fiyat</th>
<th>Tutar</th>
<th>Sil</th>
</tr>
@foreach (var c in Model)
{
<tr>
<td>@c.STOKADI</td>
<td style="width: 150px">
<div class="item" style="">
<button style="background-color: black; color: #fff; border: none; float: left; width: 30px; height: 30px; font-size: 15px; border-radius: 50px" data-id="@c.ID" id="maz">-</button>
<input type="text" value="@c.ID" name="ID" id="txtid" hidden />
<input type="text" value="@c.MIKTAR" name="MIKTAR" id="txtmiktar" style="border: none; text-align: center; float: left; width: 30px; height: 30px; font-size: 15px" />
<button style="background-color: black; float: left; color: #fff; border: none; width: 30px; height: 30px; font-size: 15px; border-radius: 50px" data-id="@c.ID" id="mart">+</button>
</div>
</td>
<td>@c.FIYAT</td>
<td>@((System.Data.SqlTypes.SqlMoney?)c.TUTAR) ₺</td>
<td>
<div class="item">
<input type="text" name="ID" id="silid" value="@c.ID" hidden />
<button class="btn btn-danger" id="sil">Sil</button>
</div>
</td>
</tr>
}
</table>
</div>
<script>
$(document).ready(function () {
document.getElementById("printdiv").style.visibility = "hidden";
});
function PrintFunction(div) {
document.getElementById("printdiv").style.visibility = "visible";
Popup($(div).html());
}
function Popup(data) {
var printwindow = window.open('', 'printdiv');
printwindow.document.write('<html><head><title></title>');
printwindow.document.write('</head><body>');
printwindow.document.write(data);
printwindow.document.write('</body><html>');
printwindow.document.close();
document.getElementById("printdiv").style.visibility = "hidden";
printwindow.focus();
printwindow.print();
printwindow.close();
document.getElementById("printdiv").style.visibility = "hidden";
}
</script>