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
Now If I right click on 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.
Solution
Just right click on references ,select add reference click browser button of selection manager window go to path and add references like this.
精彩评论