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

the*_*ner 9 jquery web-services asp.net-ajax asmx

我正在使用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();
}
}
Run Code Online (Sandbox Code Playgroud)

Jag*_*mag 14

System.Web.Services.dll在项目中添加引用.

您很可能因为已经有正确的using声明而错过了这个错误

  • 我相信你的意思是写"使用System.Web.Services;"对我来说就像一个魅力感谢. (7认同)