title: How to implement printing in ASP.Net MVC3
body: <p>As part of my current task in a given list of items, user can select some of them and invoke 'Print' no the selected items.</p>
  
  <p>For each selected item we need to print the details. It is similar to printing invoices of selected items in a sales system.</p>
  
  <p>I have created a partial view to write each record details but I am not sure how to use it as per my requirement.</p>
  
  <p>Can I call jQuery print on document.ready to achieve my requirement?</p>
  
  <p>As @Levib suggested, calling partial view in my PrintView. And PrintView's document.reay function is calling window.print. But when I try to invoke 'Print', I can not see print dialogue.</p>
  
  <p>This is my view,</p>
  
  <pre><code>@section Styles
  {
      &lt;link rel="stylesheet" href="AdminStyle.css" type="text/css" media="all" /&gt;
      &lt;link rel="stylesheet" href="AdminPrintOrder.css" type="text/css" media="print" /&gt;
  }
  
  @foreach (var item in Model)
  {
      &lt;div id="content" style="page-break-before: always"&gt;
          @{Html.RenderPartial("_OrderDetailView", item);}
      &lt;/div&gt;   
  }
  
  @section scripts
  {
      &lt;script type="text/javascript"&gt;
          $(document).ready(function () {
              debugger;
              window.print();
          });
      &lt;/script&gt;
  }
  </code></pre>
  
  <p>And my print invoker view is</p>
  
  <pre><code> function printInvoices(){
              $.ajax({
                  type: 'POST',
                  url: '/Batch/PrintInvoices',
                  data: '{ "allocationId" : "' + unSelected.toString() + '"}',
                  contentType: "application/json; charset=utf-8",
                  traditional: true,
                  success: printedView,
                  error: errorInSubscribing
              });
          }
  </code></pre>
  
  <p><strong>Do I need to handle ajax reposne to populate print dialogue.</strong></p>
  
  <pre><code> function printedView() {
              unSelected = [];
          }
  </code></pre>
  
  <p>And controller action is</p>
  
  <pre><code>[HttpPost]
          public ActionResult PrintInvoices(string allocationId)
          {
              var context = new BatchContext();
              var orderDetails =  context.GetOrderDetails(RetriveList(allocationId));
              return View(orderDetails);
          }
  </code></pre>