2010-11-07 159 views
8

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

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(); 
} 
} 

回答

13

在您的项目中添加对System.Web.Services.dll的引用。

这是最有可能对你的思念已经意识到了这个错误,因为你已经有了正确的using声明

+6

我相信你的意思是只写'使用System.Web.Services;'就像我非常感谢神韵。 – Anicho 2011-10-21 09:35:04

0

添加以下页面的顶部:

using System.Web; 
using System.Web.UI; 
using System.Web.UI.WebControls; 
using System.Web.Services; 
0

简单的回答这个问题只需从.net框架文件夹中添加system.web.services参考。

例子:

考虑我有这已经是引用system.web.services

现在如果我右击System.web.services项目

您可以看到此程序集内部.Net路径,因此您可以轻松地从该处添加此程序集的引用。

enter image description here

解决方案

上的引用只需右键点击,选择添加选择管理器窗口中点击参考浏览器按钮进入路径,并添加这样的引用。

enter image description here

相关问题