最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

asp.net mvc 4 - Printing a div with HTML in a Partial view in mvc 4 with C# using JavaScript - Stack Overflow

programmeradmin2浏览0评论

I want to show a print in table format(design ) in c# mvc.

The problem is that i am getting only the content and not in table format..

This is my Print button.

<input id="printdiv" type="submit" value="Print" onclick="return PrintDiv();" />

This is my Partial view div.

<div id="dvmismatch" style="display :none;">
        @Html.Partial("_MismatchVendorList", Model)
    </div>

This is my Script..

<script type="text/javascript">
    var $ = jQuery.noConflict();   
    function PrintDiv() {
        $("#dvmismatch").show();
        $("#dvmismatch").print();
        $("#dvmismatch").hide();

        }       

</script>

plz give me the Suggestions...

i want to Print a div with HTML in a Partial view in mvc 4 with C# using JavaScript..But showing only the table Content. Not the Content with Table Format????

I want to show a print in table format(design ) in c# mvc.

The problem is that i am getting only the content and not in table format..

This is my Print button.

<input id="printdiv" type="submit" value="Print" onclick="return PrintDiv();" />

This is my Partial view div.

<div id="dvmismatch" style="display :none;">
        @Html.Partial("_MismatchVendorList", Model)
    </div>

This is my Script..

<script type="text/javascript">
    var $ = jQuery.noConflict();   
    function PrintDiv() {
        $("#dvmismatch").show();
        $("#dvmismatch").print();
        $("#dvmismatch").hide();

        }       

</script>

plz give me the Suggestions...

i want to Print a div with HTML in a Partial view in mvc 4 with C# using JavaScript..But showing only the table Content. Not the Content with Table Format????

Share Improve this question edited Aug 26, 2016 at 10:40 Rizwana Ahmed asked Aug 26, 2016 at 10:28 Rizwana AhmedRizwana Ahmed 431 gold badge1 silver badge7 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 4

Try This

Javascript

<script>
function printContent(el){
    var restorepage = document.body.innerHTML;
    var printcontent = document.getElementById(el).innerHTML;
    document.body.innerHTML = printcontent;
    window.print();
    document.body.innerHTML = restorepage;
}
</script>

Button

<input id="printdiv" type="submit" value="Print" onclick="printContent('dvmismatch')" />

This is Partial view div.

<div id="dvmismatch" style="display :none;">
        @Html.Partial("_MismatchVendorList", Model)
    </div>
发布评论

评论列表(0)

  1. 暂无评论