开发者

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

开发者 https://www.devze.com 2023-01-24 09:18 出处:网络
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 \'webme

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' 开发者_StackOverflow中文版could not be found. I have put "using System.Web.Services;" at the top. What else needs to be done?

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


Add a reference to System.Web.Services.dll in your project.

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


Add the following on top of the page:

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


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

Example:

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

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

Now If I right click on System.web.services

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

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

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

Solution

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

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

0

精彩评论

暂无评论...
验证码 换一张
取 消