0

i am trying to print the div , after printing is over, then pass the id to action method , for now it just prints alone, this is something i did :

Update: it has been solved, here simultaneously it goes to action method for calculation and provides user to print document, hope helps someone, you are welcome to make improvements further .

my view:

<script language="javascript" type="text/javascript">
    function printDiv(divID) {

     // for redirecting to action method 
     reduce();

        //For printing div
        var divElements = document.getElementById(divID).innerHTML;
        var oldPage = document.body.innerHTML;
        document.body.innerHTML =
        "<html><head><title></title></head><body>" +
        divElements + "</body>";
        window.print();
        document.body.innerHTML = oldPage;



    }

   function reduce() {
            var url = '@Url.Action("Reduce", "Home", new { id = "__id__" })'
    window.location.href = url.replace('__id__', @selectpricedetails.PriceId);
        }
</script> 

 @using (Html.BeginForm("Reduce", "Home", FormMethod.Post))
    {

    foreach (var selectpricedetails in ViewBag.SelectGift)
     {
    @Html.Hidden("id", ((ViewBag.SelectGift as 
    ICollection<AllPoints.Models.Price>).First().PriceId));

    <input id="redeem" type="submit" class="btn btn-primary" value="REDEEM THIS" 
    onclick="printDiv('printthis');">

   // i placed my <script> </script> here to get id and pass to Action  Method        

    <div id="printthis" class="col-md-9">

     </div>


    }
 }

Action method :

public ActionResult Reduce(FormCollection col, int id = 0)
{

// here doing some calculations using id

}

i am not sure if its possible, any help would be great.

Shaiju T
  • 6,201
  • 20
  • 104
  • 196
  • 2
    Hmmm.. I don't think there is an `event` you can tie the call to redirect to once printing has finished. I'd be interested to find out if there is though. To my mind, you'd call the print action and then the redirect would happen straight after (in tandom) with it. – scgough Mar 11 '15 at 08:34
  • @scgough, i have edited , and now it works fine , i got the small tip from reading your comment , i just paced the redirect function in top inside the print function, this meets my requirement , thank you. – Shaiju T Mar 11 '15 at 09:45
  • 1
    check this http://stackoverflow.com/questions/18325025/how-to-detect-window-print-finish – A Khudairy Mar 11 '15 at 09:46
  • 1
    @ A Khudairy , thank you for the link, that was good, if needed i will implement it – Shaiju T Mar 11 '15 at 09:54

0 Answers0