ASP.NET Core MVC Controls | ComponentOne
Working with Controls / Input Controls / AutoComplete / Work with AutoComplete / Custom Action
In This Topic
    Custom Action
    In This Topic

    Custom action is an another important feature, when you are working with AutoComplete in your MVC application. You can specify custom actions, that you want to perform using AutoComplete control. For example, in the code below we are using custom actions to filter data after certain number of characters are typed by a user.

    The following image shows how the AutoComplete appears after using custom actions.

    The following code example demonstrates how to use custom action in AutoComplete:

    AutoCompleteController.cs

    Razor
    Copy Code
    public ActionResult Index()
            {
                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);
            }
    

    AutoComplete.cshtml

    Razor
    Copy Code
    <div>
        <label>Custom action</label>
        <c1-auto-complete items-source-action="@Url.Action("Heuristic")">
        </c1-auto-complete>
    </div>