简体   繁体   English

从ajax作为null发送到MVC控制器的数据

[英]Data sent from ajax as null into the MVC controller

I got JS function which use ajax . 我有使用ajax JS函数。 It calls the controller which suppose to get data and parse it. 它调用控制器,它假设获取数据并解析它。 It ssems like on client side data variable formed ok bu the controller gets nothing! 它像客户端数据变量形成的确定没有控制器什么都没有!

I call JS function like getTheDiagramm('/PPTDesign/getReceiversDiagram', recIntervalsRec.total, recIntervalsRec.records); 我将JS函数getTheDiagramm('/PPTDesign/getReceiversDiagram', recIntervalsRec.total, recIntervalsRec.records);

Here's the function as is 这是功能原样

 function getTheDiagramm(action_url, total_d, records_d) {

                        var mainData;

                        var table_form = {
                            total: total_d,
                            records: records_d
                        }
                        var postData = JSON.stringify(table_form);

                        $.ajax({
                            type: "POST",
                            url: action_url,
                            async: false,
                            data: postData,
                            dataType: "json",
                            contentType: "application/json; charset=utf-8",
                            success: function (data) {
                                mainData = data;
                            }
                        });

                        return mainData;
                    }

On the controller side 在控制器方面

  public JsonResult getReceiversDiagram(DesignReceiversMap postData)
        {
            List<string> resultData = new List<string>();
            return Json(resultData, JsonRequestBehavior.AllowGet);

        }

Models 楷模

public class Design {
        public int recid;
        public String well;
        public String q1;   
        public String q2; 
        public String down; 
        public String up; 
    }

    public class DesignReceivers : Design {
        public String period1; 
        public String period2;
    }
    public class DesignReceiversMap {
        public int total;
        public List<DesignReceivers> records;
    }

So, what it sends 那么,它发送了什么 http://i.gyazo.com/d5ef811e0f32e77f29bb4fe1331f9980.png

and what controller gets 什么控制器得到 http://i.gyazo.com/660bfd8b3808328d974c1c2b89993249.png

I really don't understand what's wrong. 我真的不明白什么是错的。 Could you help me to fix it, please? 你能帮我解决一下吗?

Your method public JsonResult getReceiversDiagram(DesignReceiversMap postData) expects DesignReceiversMap object as input. 您的方法public JsonResult getReceiversDiagram(DesignReceiversMap postData)需要public JsonResult getReceiversDiagram(DesignReceiversMap postData)对象作为输入。 But that's not what you send when you call the method. 但是,当你调用方法时,这不是你发送的内容。

Try this in your controller: 在你的控制器中尝试这个:

public JsonResult getReceiversDiagram(string postData)

and this in your js: 这在你的js中:

$.ajax({
    type: "POST",
    url: action_url,
    async: false,
    data: "postData=" + postData,
    success: function (data) {
        mainData = data;
    }
});

then you can parse the data. 然后你可以解析数据。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM