2017-12-31 312 views
0

ajaxとIHttpActionResultを使用して、C#.net(VS2017)のWeb APIに配列をポストすることができます。しかし、vb.net(VC2017)にコードを変換した後は動作しません。私は変数の値を0にします。ここに私のコードは次のとおりです。VBで動作していないIHttpActionResultを使用して配列をWeb APIにポストする

クラス:

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); 
     }); 

クロームF12 enter image description here

答えて

3

あなたのプロパティ名は

var latlon = [ 
     { lat: 45, lon: -120 }, 
     { lat: 55, lon: -112 } 
    ]; 

VBクラスで

Public Class Latlon 
    Public Property latIn As Decimal 
    Public Property lonIn As Decimal 
End Class 

Public Class Latlon 
    Public Property lat As Decimal 
    Public Property lon As Decimal 
End Class 
+0

はそんなに、ケンありがとうVBクラスのプロパティの名前を変更してみてくださいと同じではありませんと一致しません!あなたは何時間も私を救った。変換後、変数名を変更したため、問題が発生しました。私はそれを実現しませんでした。明けましておめでとうございます! – user1617676

関連する問題