【发布时间】:2018-01-01 02:52:29
【问题描述】:
我可以使用 ajax 和 IHttpActionResult 在 C#.net (VS2017) 中将数组发布到 web api。但是,在我将代码转换为 vb.net (VC2017) 后它不起作用。我只得到变量的 0 值。这是我的代码:
类:
Public Class Latlon
Public Property latIn As Decimal
Public Property lonIn As Decimal
End Class
API 控制器
<HttpPost>
Public Function Post(ByVal latlons As List(Of Latlon)) As IHttpActionResult
Dim lat1 = latlons(0).latIn
Return Content(HttpStatusCode.BadRequest, lat1)
End Function
ajax:
var latlon = [
{ lat: 45, lon: -120 },
{ lat: 55, lon: -112 }
];
alert(latlon)
$.ajax({
url: uri,
method: "POST",
data: { '': latlon }
}).done(function (result) {
alert(result)
}).fail(function (xhr) {
alert(xhr.responseText);
});
【问题讨论】:
标签: arrays json vb.net post asp.net-web-api