How to print a View in default printer using JavaScript or C #?

3

I need to print the contents of a view on the default printer. How can I do this using C # or javascript?

    
asked by anonymous 18.03.2015 / 12:28

1 answer

1

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 .

    
18.03.2015 / 12:38