2015-07-10 54 views
1

我在我的ASP.NET项目中使用token-input plugin令牌输入无法访问ASP.Net Web方法

我有一个Web方法如下图所示,

public partial class User : System.Web.UI.Page 
{ 
    [WebMethod] 
    public static List<IdAndName> GetDescriptions() 
    { 
     return DBQueryManager.GetDistinctDescriptions(); 
    } 
$('#DescriptionFilterTxtBox').tokenInput("User.aspx/GetDescriptions", { 
    hintText: "Key in atleast 2 chars. First 20 match is displayed.", 
    searchDelay: 25,     
    minChars: 1, 
    resultsLimit: 10, 
    tokenValue: name 
}); 

我试图从GetDescriptions方法获取数据,并在DescriptionFilterTxtBox显示它,但它不工作。基本上,该插件无法击中网络方法。

如何从tokeninput插件打到ASP.Net Web方法?任何帮助/建议表示赞赏。

+0

该控件不会GetDescriptions()? – Sachu

+0

@Sachu,是的。它无法在aspx页面中点击webmethod。 –

+0

我使用了mvc..for aspx上的插件,大多数的ppl建议创建一个jason函数并使用url参考[http://stackoverflow.com/questions/25664448/token-input-not-working] – Sachu

回答

0

你的方法需要q参数:

[WebMethod] 
public static List<IdAndName> GetDescriptions(string q) 
{ 
    return DBQueryManager.GetDistinctDescriptions(); 
} 

脚本必须接受一个GET参数为q其中将包含这个词来搜索。例如。 http://www.example.com/myscript?q=query

jquery-tokeninput

您还需要从方法返回一个JSON。