0

印刷ボタンと印刷メソッドがありますが、この 2 つをリンクする必要がありますか?

印刷ボタンでこのメソッドpublic ActionResult Print(int id)を呼び出す必要があります。

2つを接続する方法がわかりません。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})'
    });
    });
4

1 に答える 1

3
$('#btnPrint').click(function() {
    // Call the controller function, put it where you need it.
    $.ajax({
        url: '@Url.Action("Print","ContractController", new {id = Model.SalesContractId})'
    });


    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
    }​
});
于 2012-05-31T06:29:35.740 に答える