簡體   English   中英

使用參數從javascript調用控制器Actinresult類型的操作

[英]call controller Actinresult type action from javascript with parameter

我嘗試以下方式:

我的動作是:

[HttpPost]
        public ActionResult PaymentVoucherCommit(string sParameter)
        {
            try
            {
                _oVoucher = new Voucher();
                _oVoucher = _oVoucher.CommitVoucherNo(2, 1); // Here 2 refere VoucherTypeID that is PaymentVoucher & 1 refere jam company ID
                _oVoucher.BaseCurrencyId = 1; //jas......this code is temporary 
                _oVoucher.CompanyID = 1;//jas......this code is temporary 
                _oVoucher.VoucherTypeID = 2;//jam for temporary basis code 2 is paymenttypeid that is payment voucher
                _oVoucher.CurrencyId = 1;
                _oVoucher.BaseCurrencyNameSymbol = "Taka[Tk]"; //jas......this code is temporary
                _oVoucher.VoucherDetailLst = VoucherDetail.Gets(_oVoucher.VoucherID);
                _oVoucher.LstCurrency = Currency.Gets();
                _oVoucher.Operation = "AddPaymnetVoucher";
                _oVoucher.DebitAccountHeadName = "Press Enter";
                _oVoucher.CreditAccountHeadName = "Press Enter";
                return View(_oVoucher);
            }
            catch (Exception ex)
            {
                return View(ex.Message);
            }
        }

我的JavaScript代碼是:

$('#btnCommit').keypress(function (e) {
        debugger;
        var keyCode = e.keyCode || e.which;
        if (keyCode == 13) {
            $.ajax({
                type: "POST",
                dataType: "text json",
                url: '@Url.Action("PaymentVoucherCommit", "Voucher")',
                data: { sParameter: "Bangladesh" },
                contentType: "application/json; charset=utf-8",
                success: function (data) {
                    //                        debugger;
                    alert(data);
                },
                error: function (xhr, status, error) {
                    alert(error);
                }
            });
            return false;
        }
    })

請修復此錯誤。

注意:相同類型的任務我已成功完成[httpGet]請求。 但是ia triad用於發布類型的動作(動作結果)

簡單嘗試:

$('#btnCommit').keypress(function (e) {
    debugger;
    var keyCode = e.keyCode || e.which;
    if (keyCode == 13) {
        $.post('@Html.Raw(Url.Action("PaymentVoucherCommit", "Voucher"))', { sParameter: "Bangladesh" }, function(view){
             alert(view);
        });
        return false;
    }
})

如果要返回Json,則:

[HttpPost]
    public JsonResult PaymentVoucherCommit(string sParameter)
    {
        try
        {
            _oVoucher = new Voucher();
            _oVoucher = _oVoucher.CommitVoucherNo(2, 1); // Here 2 refere VoucherTypeID that is PaymentVoucher & 1 refere jam company ID
            _oVoucher.BaseCurrencyId = 1; //jas......this code is temporary 
            _oVoucher.CompanyID = 1;//jas......this code is temporary 
            _oVoucher.VoucherTypeID = 2;//jam for temporary basis code 2 is paymenttypeid that is payment voucher
            _oVoucher.CurrencyId = 1;
            _oVoucher.BaseCurrencyNameSymbol = "Taka[Tk]"; //jas......this code is temporary
            _oVoucher.VoucherDetailLst = VoucherDetail.Gets(_oVoucher.VoucherID);
            _oVoucher.LstCurrency = Currency.Gets();
            _oVoucher.Operation = "AddPaymnetVoucher";
            _oVoucher.DebitAccountHeadName = "Press Enter";
            _oVoucher.CreditAccountHeadName = "Press Enter";
            return Json(_oVoucher);
        }
        catch (Exception ex)
        {
            return Json(ex.Message);
        }
    }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM