AutoComplete
AutoComplete
Incremental Search
Features
Sample
Search for types in mscorlib:
Description
This sample shows how to provide incremental search by using custom action as data source for AutoComplete control.
Source
CustomActionController.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using C1.Web.Mvc.Serialization;
namespace MvcExplorer.Controllers
{
public partial class AutoCompleteController : Controller
{
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);
}
}
}
CustomAction.cshtml
@section Styles{
<style>
.highlight {
background-color: #ff0;
color: #000;
}
</style>
}
<div>
<label>@Html.Raw(Resources.AutoComplete.CustomAction_Text1)</label>
@(Html.C1().AutoComplete()
.ItemsSourceAction(Url.Action("Heuristic"))
)
</div>
<div>
<label>@Html.Raw(Resources.AutoComplete.CustomAction_Text2)</label>
<p>@Html.Raw(Resources.AutoComplete.CustomAction_Text0)</p>
@(Html.C1().AutoComplete()
.MaxItems(10).CssMatch("highlight")
.ItemsSourceAction(Url.Action("TypesInMscorlib"))
)
</div>
@section Description{
@Html.Raw(Resources.AutoComplete.CustomAction_Text3)
}
Documentation