Link to home
Start Free TrialLog in
Avatar of Intelli-Seeker
Intelli-SeekerFlag for United States of America

asked on

Print contents of dropdown list in ASP.NET MVC

I want to print the contents of a dropdown list and the other items in my view. Rather than printing the selected content in the dropdown list, it just prints the first item in the list. I pasted a portion of my controller code below. I am using jQuery within an ASP.NET MVC 5 project.

(sidenote: I do not have a submit button yet. My plan is to use the submit button to send the completed form by email to the purchasing department. That is the next hurdle I have to tackle.)

<div class="col-md-12" , id="Envelopes">
    <h2>
        Envelopes
    </h2>

    <p>
        Please enter the quantity and click submit to send an email to the appropriate purchasing department.
    </p>
    <p>
        <table class="table" , id="EnvelopeTable">
            <thead>
                <tr>
                    <th>Product</th>
                    <th>Quantity</th>
                </tr>
            </thead>
            <tbody>
                <tr>
                    <td>@Html.DropDownList("Products", "Select Products")</td>
                    <td><input type=""</td>
                </tr>
            </tbody>
        </table>
    </p>
    <div>
        @*jQuery script below creates a print contents of a div. Give the div tag an id*@
        <p>
            <script>
                function printContent(el) {
                    var restorepage = $('body').html();
                    var printcontent = $('#' + el).clone();
                    $('body').empty().html(printcontent);
                    window.print();
                    $('body').html(restorepage);
                }
            </script>
            <button id="print" onclick="printContent('Envelopes');">Print</button>
        </p>
        <br />
    </div>
    <br>

Open in new window


I can attach the view code if needed and/or a copy of the model.
Avatar of kaufmed
kaufmed
Flag of United States of America image

Why do you have commas in your element attributes?

User generated image
Avatar of Intelli-Seeker

ASKER

As far as the commas in the attributes, I was copying from some else's code.
This question needs an answer!
Become an EE member today
7 DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform.
View membership options
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.