【问题标题】:Unable to send data from actionResult to asyn mothod in mvc无法将数据从 actionResult 发送到 mvc 中的异步方法
【发布时间】:2015-08-14 05:53:37
【问题描述】:

这是我的控制器 actionReslt

[ValidateAntiForgeryToken()] 
    public ActionResult PaymentDetails(PaymentViewModel payment)
    {
        PaymentModel paymentModel = new PaymentModel();
        //  AutoMapper.Mapper.CreateMap<PaymentModel, PaymentViewModel>();
        if (ModelState.IsValid)
        {               

            CreditCardDetailsModel creditCardDetailsModel = new CreditCardDetailsModel();
            creditCardDetailsModel.SecurityId = payment.SecurityId;
            creditCardDetailsModel.ExpiryDate = payment.Month + payment.Year;
            creditCardDetailsModel.CardNumber = payment.CardNumber;
            paymentModel.CreditCardDetails = creditCardDetailsModel;
            return RedirectToAction("Payment",paymentModel);
        } 
        return View("FlightBooking");
    }

这是我的异步方法

  public async Task<JsonResult> Payment(PaymentModel model)
    {
        CreateFormOfPaymentReplyModel response = new CreateFormOfPaymentReplyModel();
        resource = Constants.Payment;
        response = await Post<CreateFormOfPaymentReplyModel>(model);

        resource = Constants.PnrConfirm;
        var pnrConformStatus = await Get<PNRConfirmResponseModel>();
        return new JsonResult { Data = new { status = false, message = response } };

    }

如果paymentObject有效但PaymentModel返回空数据并且错误显示为

This request has been blocked because sensitive information could be disclosed to third party web sites when this is used in a GET request. To allow GET requests, set JsonRequestBehavior to AllowGet

【问题讨论】:

  • JsonResult { Data = new { status = false, message = response }, JsonBehaviour.AllowGet };试试这个
  • 我没听明白,我想与数据(paymentmodel)一起重定向到付款方式,但在进入付款方式后我得到空数据

标签: asp.net-mvc asp.net-mvc-4 jsonresult


【解决方案1】:

您是否尝试过将 allowget 传递给您的返回变量?

即:

 return Json( new { status = false, message = response }, JsonRequestBehavior.AllowGet);

希望这会有所帮助。

【讨论】:

    猜你喜欢
    • 2016-05-30
    • 1970-01-01
    • 2013-01-14
    • 1970-01-01
    • 2019-11-04
    • 2021-01-28
    • 1970-01-01
    • 1970-01-01
    • 2022-08-18
    相关资源
    最近更新 更多