如何使用Entity和Linq实现自动完成文本框 [英] How to implement auto complete textbox using Entity and Linq
本文介绍了如何使用Entity和Linq实现自动完成文本框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在我的应用程序中使用实体框架,我使用linq自动完成文本框。在调试模式下,它会检索值,但页面城市名称不显示。我做错了什么?
I am using entity framework in my application in that i autocomplete textbox using linq . In debug mode it retrive value but in page city name not display.Am i doing something wrong?
[System.Web.Script.Services.ScriptMethod()]
[System.Web.Services.WebMethod]
public static List<string> GetSuggessions(string prefixText, int count, string contextKey)
{
List<string> res = MasterDTO.GetCities(21).Select(s => s.CityName).ToList();
List<string> suggestions = res
.Where(a => a.StartsWith(prefixText))
.Take(count)
.ToList();
// contextKey can be used to set further filter
return suggestions;
}
<asp:ScriptManager ID="ScriptManager2" EnablePageMethods ="true" runat="server" />
<asp:TextBox ID="txtAutoComplete" runat="server" ></asp:TextBox>
<ajax:AutoCompleteExtender ID="AutoCompleteExtender1" runat="server" TargetControlID="txtAutoComplete" runat="server" MinimumPrefixLength="1"
EnableCaching="true"
CompletionInterval="100"
ServiceMethod="GetSuggessions"
CompletionSetCount="20"
ContextKey="strOtherPram">
</ajax:AutoCompleteExtender>
推荐答案
尝试如下。
Hi,
try like below.
[System.Web.Services.WebMethod]
[System.Web.Script.Services.ScriptMethod]
public string[] GetSuggessions(string prefixText, int count, string contextKey)
{
List<string> res = MasterDTO.GetCities(21).Select(s => s.CityName).ToList();
string[] suggestions = res.Where(a => a.StartsWith(prefixText)).ToList().ToArray();
// contextKey can be used to set further filter
return suggestions;
}
因为,网络方法签名应如下所示。
because, the web method signature, should be like below.
[System.Web.Services.WebMethod]
[System.Web.Script.Services.ScriptMethod]
public string[] GetSuggessions(
string prefixText, int count, string contextKey) { ... }
函数应返回字符串数组。
参考自动完成演示 [ ^ ]了解更多
这篇关于如何使用Entity和Linq实现自动完成文本框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文