我有以下变量:
var atributos = [{Atributo: "Autor", Valor: ""},
{Atributo: "Titulo", Valor: ""},
{Atributo: "Documento de/até", Valor: " :: "},
{Atributo: "Conteudo", Valor: ""}]
这个AJAX请求:
$.ajax({
type: "POST",
url: "GestaoFicheiros.aspx/FuncaoPesquisar",
contentType: "application/json; charset=utf-8",
dataType: "json",
data: {Atributos:JSON.stringify(atributos)},
async: false,
success: function (data) {
},
error: function (xhr, textStatus, errorThrown) {
console.log(xhr);
alert('request failed:\nxhr:' + xhr + '\nTextSatus:' + textStatus + '\nError thrown:' + errorThrown);
}
});
但是,它给了我一个500
错误。 WebMethod
如下:
[WebMethod]
public static void FuncaoPesquisar(List<AtributoInput> Atributos){
Debug.WriteLine("received");
foreach(AtributoInput attr in Atributos)
{
Debug.WriteLine(attr.Atributo + " - " + attr.Valor);
}
}
还有Atributoinput
类:
public class AtributoInput
{
private string _Atributo;
private string _Valor;
public string Atributo
{
get { return _Atributo; }
set { _Atributo = value; }
}
public string Valor
{
get { return _Valor; }
set { _Valor= value; }
}
}
有人知道为什么这行不通吗?
WriteLine
无法打印。
谢谢!