0

我尝试以下方式:

我的行动是:

[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 for post type action(Action Result)

4

1 回答 1

0

尝试简单:

$('#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);
        }
    }
于 2012-10-08T07:47:49.357 回答