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.