我有一个打印按钮和一个打印方法,我需要将两者联系起来吗?
我需要让打印按钮调用此方法public ActionResult Print(int id)。
我不确定如何将两者联系起来,我确定有很多选项我只是在寻找最简单的选项,如果将代码添加到 html 或 jQuery 我不介意。
可以请给我看看。提前致谢 :)
创建到我的按钮:
<input type="button" value="Print" id="btnPrint" />
下面是我的控制器:
namespace Contract.Controllers
{
public class ContractController : Controller
{
CompassEntities db = new CompassEntities();
public ActionResult Index()
{
IEnumerable<tbSalesContract> contracts = db.sptbSalesContractsGetForUser(Environment.UserName.Trim() + "_comps").AsEnumerable();
return View(contracts);
}
public ActionResult Print(int id)
{
return View(""); // This can be removed and Print code may be added
}
public ActionResult Edit(int? id)
{
tbSalesContract c = new tbSalesContract();
c.Suretyship = true;
if (id != null)
{
c = db.tbSalesContracts.Find(id);
}
ViewBag.UserName = Environment.UserName.Trim();
//ContractInstance c = new ContractInstance();
return View(c);
}
已经可以使用 JQuery 设置动作的打印按钮:
$('#btnPrint').click(function () {
if ($('#chkFinal').is(':checked')) {
$(function () {
$("#PrintDialog").dialog('close');
});
}
else {
$('#chkFinal').attr('checked', true); // Set finalized. This checkbox is not visible its like a hidden field
$('#btnSubmit').click(); // Save
}
我目前所拥有的,编译但不带我打印方法:
// Save, set state to finalized and Print
$('#btnDialogPrint').click(function () {
if ($('#chkFinal').is(':checked')) {
$(function () {
$("#PrintDialog").dialog('close');
});
}
else {
$('#chkFinal').attr('checked', true); // Set finalized. This checkbox is not visible its like a hidden field
$('#btnSubmit').click(); // Save
}
$.ajax({
url: '@Url.Action("Print","ContractController", new {id = Model.SalesContractId})'
});
});