C# 如何从类函数获得Ajax响应?

C# 如何从类函数获得Ajax响应?,c#,javascript,jquery,asp.net,ajax,C#,Javascript,Jquery,Asp.net,Ajax,我有一门课:- namespace CodeFiles { public class GetDetails { public List<string> AllItems(string value) { string[] items = { "hassaan", "samina", "noureen", "hafsa", "wajeeh", "farnaz", "basim", "shahnaz" };

我有一门课:-

 namespace CodeFiles
 {
 public class GetDetails
 {

      public List<string> AllItems(string value)
      {
            string[] items =  { "hassaan", "samina", "noureen", "hafsa", "wajeeh", "farnaz", "basim", "shahnaz" };
            var lst = new List<string>();
            return (from o in items
                    where o.Contains(value)
                    select o).ToList();
      } 
   }
}
我在
url处收到错误:“CodeFiles.GetDetails.cs/AllItems”
导致错误。
如何实现这一点。

您不能将类名作为url传递。您只需传递ajax响应文件的url。

这是一个web应用程序,对吗

如果是这种情况,则创建一个webform,或者如果已经存在,则只需创建一个静态方法,并使用[WebMethod]装饰,然后在方法内部初始化类并调用方法AllItems

简单的例子:

在Default.aspx上:

[WebMethod]
public static string Hello(string name)
{
    return name;
}
然后在js中:

function Hello() {
    $.ajax({
        type: "POST",
        url: "Default.aspx/Hello",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function (result) {
            response(result.d);
        },
        error: function (result) {
            alert('There is a problem processing your request');
        }
    });
}
function Hello() {
    $.ajax({
        type: "POST",
        url: "Default.aspx/Hello",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function (result) {
            response(result.d);
        },
        error: function (result) {
            alert('There is a problem processing your request');
        }
    });
}