我有多个参数必须传递给 api 控制器。
我正在做的是
在我的 javascript
var routeInfo = JSON.stringify(routes);
var colors = JSON.stringify(colorsArray);
var times = JSON.stringify(mytimeArray);
var distances = JSON.stringify(myDistancArray);
var dir = $("#Direction").val();
var fullString = routeInfo + ";" + colors + ";" + times + ";" + distances+";"+dir;
$.post("api/HomeToSchool/?route=" + fullString,
function (data) {
if (data = true) {
alert("Routes Saved Successfully");
}
else if (data = false) {
alert("Routes are not saved");
}
});
& 在我的控制器中
public bool PostHomeToSchoolRoutes([FromUri]string route)
{
// my logic
}
在这里,我只是得到“routeInfo”的值,而其他值没有出现。例如
var routeInfo = [["Børge,Brogade 38, 4100, Ringsted,09:25:00,55.43953, 11.79043","Grete,Sjællandsgade 27, 4100, Ringsted,09:25:00,55.44024, 11.78852","Else,Fynsgade 14, 4100, Ringsted,09:25:00,55.44128, 11.78595","Birthe,Eksercerpladsen 47, 4100, Ringsted,09:25:00,55.44954, 11.80309","Knud Lavard Centret, Eksercerpladsen 3, 4100, Ringsted,370,55.45014, 11.80474"]]
var colors = ["#886A52"]
var times = [7.97]
var distances = [3.36]
var dir = 0
我在控制器中得到的是
[["Børge,Brogade 38, 4100, Ringsted,09:25:00,55.43953, 11.79043","Grete,Sjællandsgade 27, 4100, Ringsted,09:25:00,55.44024, 11.78852","Else,Fynsgade 14, 4100, Ringsted,09:25:00,55.44128, 11.78595","Birthe,Eksercerpladsen 47, 4100, Ringsted,09:25:00,55.44954, 11.80309","Knud Lavard Centret, Eksercerpladsen 3, 4100, Ringsted,370,55.45014, 11.80474"]];["
其他值不会出现。我在这里做什么错了。