我有一个 .aspx 页面,我希望我的 WebMethod 返回一个 List 以便我可以从 jQuery ajax 调用中调用它并获得 JSON 类型的响应......这是我的代码,但它只返回一个空白页面?
任何帮助都会很棒
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Services;
using System.Data.SqlClient;
using System.Configuration;
using System.Data;
using System.Web.Services.Protocols;
using System.Web.Script.Services;
namespace Test.webservices.mainGrid
{
public partial class staffTreeView : System.Web.UI.Page
{
[WebMethod()]
public static List<Staff> GetStaff()
{
try
{
List<Staff> staff = new List<Staff>();
// HttpCookie _userinfo = HttpContext.Current.Request.Cookies["userinfo"];
string connectionstring = ConfigurationManager.ConnectionStrings["TestProduction"].ConnectionString;
SqlConnection connection = new SqlConnection(connectionstring);
string sql = "sd_STAFFTREEVIEW";
SqlCommand command = new SqlCommand(sql, connection);
command.CommandType = CommandType.StoredProcedure;
SqlDataReader dr = command.ExecuteReader();
while (dr.Read())
{
staff.Add(new Staff()
{
id = dr.GetString(dr.GetOrdinal("id")),
NAME = dr.GetString(dr.GetOrdinal("NAME")),
PARENT = dr.GetString(dr.GetOrdinal("PARENT")),
VALUE = dr.GetString(dr.GetOrdinal("VALUE")),
VALUETYPE = dr.GetString(dr.GetOrdinal("VALUETYPE"))
});
}
dr.Close();
return staff;
}
catch (Exception ex)
{
throw new System.Exception("No Data Returned:" + ex.Message);
}
}
public class Staff
{
public string id { get; set; }
public string NAME { get; set; }
public string PARENT { get; set; }
public string VALUE { get; set; }
public string VALUETYPE { get; set; }
}
}
}