I need to print the contents of a view on the default printer. How can I do this using C # or javascript?
I need to print the contents of a view on the default printer. How can I do this using C # or javascript?
One alternative is to call the function print()
of JavaScript
. It would look like this:
This CSS serves only to not show the print button by clicking on it
@media print
{
.no-print, .no-print *
{
display: none !important;
}
}
And in your View
you add the button to print
<div>
<h3>Teste Impressão!</h3>
</div>
<div class="no-print">
<button type="button" value="imprimir" onclick="window.print();">Imprimir</button>
</div>
And in your View
you add the button to print.
You can see the example working at DotNetFiddle .