[英]C# pass parameter from ajax call to class
I have an ajax call like so: 我有一个像这样的ajax调用:
var is_where = true;
$.get("/api/airport/getListItems", { where: is_where}, function (data) {
});
And I am trying to pass it here: 我正在尝试通过这里:
public class AirportClass{
public List<AirportClass> getListItems(string where = null){
}
}
and I put a break point on my public List and where is still equal null when I am expecting true, am i passing this in wrong? 并且我在公共列表上设置了一个断点,当我期望为真时,哪里仍然等于null,这是我错了吗? if so, how would I fix it? 如果是这样,我该如何解决?
I think you need to specify the content type as JSON (as Ive seen from my experience) 我认为您需要将内容类型指定为JSON(从我的经验中可以看出)
var is_where = true;
$.ajax({
type: 'POST',
url: '/api/airport/getListItems',
data: is_where,
contentType: 'application/json; charset=utf-8',
dataType: 'json',
success: function(data) {
}
});
The Value your passing is Bool, pls change your method signature to : 您传递的值是Bool,请将您的方法签名更改为:
public class AirportClass{
public List<AirportClass> getListItems(bool where){
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.