首页 > 解决方案 > 无法通过弹出窗口将对象传递给控制器​​方法

问题描述

从 ajax 调用中,我得到一些数据,我想通过单击按钮传递到另一个窗口。我成功接收了数据,但是当该数据被传递时,在控制器方法参数中接收的值为 null。

<script>
    $(document).ready(function () {
        $('#btnSalesInAmount').click(function () {
            var data = {
                toDate: $('#todatepicker').val(),
                fromDate: $('#fromdatepicker').val(),
                customerId: $('#CustomerId').val()
            };
            $.ajax({
                type: 'Get',
                url: '/Reports/SalesInAmount' + '?toDate=' + data.toDate + '&fromDate=' + data.fromDate + '&customerId=' + data.customerId,
                data: data,
                success: function (data) {                       
                    window.open("/Reports/SalesInAmountView" + '?salesInAmount=' + data, 'SalesInAmountViewWindow', "features");// the data is not received by controllers method
                }
            });
        });
    });
</script>

在控制器中

 public ActionResult SalesInAmountView(SalesInAmount salesInAmount) // parameter value is null
    {
        return View();
    }

该模型

   public class SalesInAmount
{
    public DateTime SalesDt { get; set; }
    public int SalesSl { get; set; }
    public int CustomerSupplyId { get; set; }
    public string CustomerSupplyNm { get; set; }
    public double TotalSalesByCustomer { get; set; }
    public double TotalDiscount { get; set; }
    public double TotalVat { get; set; }
    public double TotalSales { get; set; }
    public List<SalesInAmount> List { get; set; }
}

标签: javascriptc#jqueryasp.net-mvcpopup

解决方案


尝试这个 ,

简化您的数据集,

 var Param1= $('#ID').val();
 var Data = JSON.stringify({ Data1 : Param1, . . });

阿贾克斯

$.ajax({
                url: '@Url.Action("Action_Name", "Controller_Name")',
                dataType: "json",
                contentType: "application/json; charset=utf-8",
                type: "POST",
                data: Data,               
                cache: false,
                success: function (data) {

                    });

                }, error: function (request, status, error) {

                }
            });

        }

控制器

 public JsonResult Action_Name(string Data1 , . . )
        {

            return Json(Some_Json);
        }

注意:此控制器返回 Json 结果,这取决于要求。


推荐阅读