In this post, we will see how we could work with Kendo AutoComplete in ASP.Net MVC. We will fetch data from SQL Server table in Kendo AutoComplete using LINQ to Sql class
Adding the Model
Follow Adding Model section of this post to create model.
Adding Controller
We have created the Model, now we need to fetch data using Model in the Controller. I am going to use default created HomeController and Action Index. Go ahead and in HomeController.cs file modify the Action Index.
Here we need to create instance of model and pass the data to view. That can be done as following
Adding Kendo AutoComplete on View
We are passing data from Index action, so we need to put Kendo AutoComplete in IndexView. Go to View and Home folder and open Index.cshtml
Very first you need to make View as strongly typed. You can make a View strongly typed as following
Next add Kendo UI AutoComplete. Make sure that you are providing the name attribute. In DataTextField pass the name of the column on which you want to filter the data.
For your reference code in view is as following
@model IEnumerable<mvcwrappersample1.Models.Person> <h3>Kendo AutoComplete</h3> @(Html.Kendo().AutoComplete() .Name("name") .DataTextField("FirstName") .BindTo(Model) .Filter("contains"))
Press F5 to run the application, you should able to get data from model in Kendo AutoComplete.
I hope you find this post useful. Thanks for reading.