我有打印按鈕和打印方法,我需要鏈接兩個?我需要將按鈕鏈接到控制器類中的函數?
我需要使打印按鈕調用此方法,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);
}
Action的打印按鈕已經可以體進行設定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})'
});
});
你想要的形式提交給行動?或者你想在chkFinal驗證完成後做一個ajax調用? –
取決於你想要'打印'做什麼。你想讓它取代整個瀏覽器窗口嗎?你是否想要更新當前窗口中的某個元素?你想讓它提供一個文件下載? –
@Jason你打我:) –