C# POST成功,但数据不可用';不要出现在控制器中

C# POST成功,但数据不可用';不要出现在控制器中,c#,asp.net,json,ajax,asp.net-core,C#,Asp.net,Json,Ajax,Asp.net Core,我正在尝试将JSON数据发布到控制器。 post成功,但数据为空 这是ajax代码: $(document).ready(function () { var result = []; $.ajax({ type: 'GET', url: 'https://api.ipdata.co/49.206.6.229?api-key=accesskey', success: function (data) { con

我正在尝试将JSON数据发布到控制器。 post成功,但数据为空

这是ajax代码:

$(document).ready(function () {
    var result = [];

    $.ajax({
        type: 'GET',
        url: 'https://api.ipdata.co/49.206.6.229?api-key=accesskey',
        success: function (data) {
            console.log(data.city),
            console.log(data.latitude),
            console.log(data.longitude),
            result= { "city": data.city, "latitude":data.latitude, "longitude":data.longitude };

            debugger
            $.ajax({
                contentType: 'application/json; charset=utf-8',
                datatype: 'JSON',
                type: 'POST',
                url: '/GeoLocation/GeoLocationData',
                data: result ,
                success: function (data) {
                    console.log(data),
                    alert('Post Successful');
                },
                error: function (data) {
                    alert('error');
                }  
            });
            debugger
        }
    });
});
我收到成功后警报,但无法使用控制器中的数据

这是我的控制器操作:

[HttpPost]
public ActionResult GeoLocationData(Location location)
{
    var city = location.city;
    var lat =  location.latitude;
    var lon =  location.longitude;
    return Ok();
}
我的模型:

public class Location
{
    public String city { get; set; }

    [Column("latitude")] 
    public double? latitude { get; set; }

    [Column("longitude")]
    public double? longitude { get; set; }
}
这是我从api获得的JSON数据:

data: { ...
   city: "xxxx", 
   continent_code: "xx" ,
   latitude: 17.3753, 
   longitude: 78.4744... }
当我检查调试器时,我可以看到数据被正确地传递,但是在第二个ajax调用中,尽管我已经给出了

数据:结果

,数据采用

JSON响应值


。为什么会这样?

根据ajax请求,尝试以下方法:

data: JSON.stringify(result),

希望这有帮助

您需要从正文中检索数据:

[HttpPost]
public ActionResult GeoLocationData([FromBody] Location location)

GeoLocationData
不返回数据。仅HTTP状态200 OK尝试使用此类=>
公共类位置{public string city{get;set;}public string continentary_code{get;set;}公共双纬度{get;set;}公共双经度{get;set;}
@Nkosi在控制器中返回JSON结果时,仍然面临相同的问题。然后我将状态更改为“确定”,但问题仍然存在:)。尝试了上述操作,但仍然存在相同的问题,因此将其还原回来!!