![](/img/trans.png)
[英]Why is my posted data null in the Controller target of this AJAX call?
[英]Why would my array on my MVC Controller be null on Ajax Postback
這是我的數組:
{latlng: [{lat: 41.9841092242239, lng: -87.6459866168}, {lat: 41.948650308164744, lng: -87.64431828280067}, {lat: 41.94833112697515, lng: -87.644017875391}]
這是我的JavaScript代碼:
var postedData = JSON.stringify({
latlng: boundaries
});
alert("here are your boundaries so far : " + postedData);
$.ajax({
url: '/Communities/UpdateBoundaries',
type: "POST",
traditional: true,
contentType: "application/json",
data: postedData,
datatype: "json",
success: function () {
console.log('success!!');
}
});
}
這是我的控制器:bounds是我傳入的latlng數組,但它為null。
[HttpPost]
public ActionResult UpdateBoundaries(List<latLng> boundaries)
{
return View();
}
更改
var postedData = JSON.stringify({latlng: boundaries});
至
var postedData = JSON.stringify(boundaries);
這是因為action參數是一個數組。 如果它是包含屬性名稱為latlng
的數組屬性的類型,則以與現有代碼相同的方式傳遞它。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.