1
我需要使用jQuery ajax請求在後面的C#代碼中處理後處理值。我可以發送數據,但我不知道如何從C#WebMethod內部檢索它。如何在C#WebMethod中獲取POST數據?
var cliente;
$.post(
"../Dados/GetDados.aspx/GetClienteById",
{
Id: id
},
function(dado) {
cliente = dado;
});
和C#代碼:
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public static string GetClienteById()
{
int PostId = What_can_I_put_here?;
string dados = "null";
using (SysContext db = new SysContext()) // I'm using Entity Framework
{
if (db.Clientes.Count(r => r.Id == PostId) > 0)
dados = new JavaScriptSerializer().Serialize(db.Clientes.Where(r => r.Id == PostId).ToList());
}
return dados;
}