jQuery 找不到类型或命名空间名称“webmethod”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4118248/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 16:42:16  来源:igfitidea点击:

the type or namespace name 'webmethod' could not be found

web-servicesjqueryasp.net-ajaxasmx

提问by thegunner

I'm using jquery, ajax, & .net to call a method. I see lots of examples on the net saying to put [Webmethod] above the method but I'm keeping getting the error the type or namespace name 'webmethod' could not be found. I have put "using System.Web.Services;" at the top. What else needs to be done?

我正在使用 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();
}
}

回答by Jagmag

Add a reference to System.Web.Services.dllin your project.

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

It is most likely missing for you to be getting this error because you already have the correct usingstatement

您很可能没有收到此错误,因为您已经有了正确的using陈述

回答by JCVA

Add the following on top of the page:

在页面顶部添加以下内容:

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

回答by JCVA

Simple answer to this question is to just Add reference of system.web.services from .net framework folder.

这个问题的简单答案是从 .net 框架文件夹中添加 system.web.services 的引用。

Example:

例子:

Consider I have a project which is already referenced system.web.services

考虑我有一个已经被引用的项目system.web.services

Now If I right click on System.web.services

现在如果我右键单击System.web.services

You can see that this assembly is inside .Net Path so you can easily add reference of this assembly in your project from there.

您可以看到此程序集位于 .Net Path 中,因此您可以从那里轻松地在您的项目中添加此程序集的引用。

enter image description here

在此处输入图片说明

Solution

解决方案

Just right click on references ,select add reference click browser button of selection manager window go to path and add references like this.

只需右键单击引用,选择添加引用单击选择管理器窗口的浏览器按钮转到路径并添加这样的引用。

enter image description here

在此处输入图片说明