MultiAutoComplete
MultiAutoComplete
Incremental Search
This sample shows how to provide incremental search by using custom action as data source for MultiAutoComplete control.
Features
Search for types in mscorlib:
Description
This sample shows how to provide incremental search by using custom action as data source for MultiAutoComplete control.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; using C1.Web.Mvc.Serialization; namespace MvcExplorer.Controllers { partial class MultiAutoCompleteController { public ActionResult CustomAction() { return View(); } public ActionResult Heuristic( string query, int max) { var prefix = new [] { "What is " , "Where to find " , "Who is best at " , "Why " , "How to make " }; return this .C1Json(prefix.Select(f => f + query + "?" ).ToList(), behavior: JsonRequestBehavior.AllowGet); } public ActionResult TypesInMscorlib( string query, int max) { var types = typeof ( object ).Assembly.GetTypes(); return this .C1Json(types .Where(t => t.FullName.ToUpper().Contains(query.ToUpper())) .Select(t => t.FullName) .Take(max).ToList(), behavior: JsonRequestBehavior.AllowGet); } } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | @section Styles{ < style > .highlight { background-color: #ff0; color: #000; } </ style > } < div > < label > @Html .Raw(Resources.MultiAutoComplete.CustomAction_CustomAction)</ label > @ (Html.C1().MultiAutoComplete() .ItemsSourceAction(Url.Action( "Heuristic" )) ) </ div > < div > < label > @Html .Raw(Resources.MultiAutoComplete.CustomAction_CustomActionWithMaxItems)</ label > < p > @Html .Raw(Resources.MultiAutoComplete.CustomAction_Text0)</ p > @ (Html.C1().MultiAutoComplete() .MaxItems(10).CssMatch( "highlight" ) .ItemsSourceAction(Url.Action( "TypesInMscorlib" )) ) </ div > @section Description{ @Html .Raw(Resources.MultiAutoComplete.CustomAction_Text1) } |