我正在尝试打印div,打印结束后,然后将id传递给action方法,现在它只是单独打印,这是我做的事情:
更新:它已经解决了,这里同时进入计算的动作方法并提供用户打印文档,希望对某人有所帮助,欢迎您进一步改进。
我的观点:
<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>
}
}
行动方法:
public ActionResult Reduce(FormCollection col, int id = 0)
{
// here doing some calculations using id
}
我不确定它是否可行,任何帮助都会很棒。