Autocomplete Extender "No item found"
I have the following webservice (.cs file) that searches for a list of products that is used in a textbox as an autocomplete extender.
public string[] GetProdDesSearch(string prefixText, int count)
{
try
{
ORDataClassesDataContext dbac = new ORDataClassesDataContext();
return dbac.tblProducts
.Where(r => r.MemberId == "123" && r.IDDesc.Contains(prefixText))
.OrderBy(r => r.IDDesc)
开发者_如何学C .Select(r => r.IDDesc)
.Distinct()
.Take(count)
.ToArray();
}
catch
{
}
return null;
}
How would I go about returning an error should a product is unable to be found? Would I specify this in the webserivce itself? I am assuming that this is where my 'catch' comes into play, but I'm not sure how to implement this exactly.
If someone could help me, I would be most grateful.
I'd say a null response or preferably an empty list clearly communicates that nothing was found, in a search method. How you want to handle that is a matter of presentation, and that should not be dealt with at all from your service. Check for null or empty lists (whatever you decide on) in your handler function
You can refer to that article Check if AutoComplete list has result items, it will help you to check if user input doesn't cause any result items from AutoComplete.
精彩评论