找不到类型或命名空间名称'webmethod'

我正在使用jquery,ajax和& .net来调用一个方法。我在网上看到很多例子说将[Webmethod]放在方法之上,但我一直在收到错误,找不到类型或命名空间名称'webmethod'。我已经把“使用System.Web.Services;”在顶部。还有什么需要做的?
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;

public partial class _Default : System.Web.UI.Page
{

[WebMethod]
public static string GetDate()
{
    return DateTime.Now.ToString();
}
}
    
已邀请:
在项目中添加对
System.Web.Services.dll
的引用。 由于您已经拥有正确的
using
语句,因此您很可能因此而错过了此错误     
在页面顶部添加以下内容:
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Services;
    
这个问题的简单答案是从.net framework文件夹中添加system.web.services的引用。 例: 考虑我有一个已经引用了system.web.services的项目 现在,如果我右键单击System.web.services 您可以看到此程序集位于.Net Path内,因此您可以从那里轻松地在项目中添加此程序集的引用。 解 只需右键单击引用,选择添加引用单击选择管理器窗口的浏览器按钮转到路径并添加这样的引用。     

要回复问题请先登录注册