O'Reilly logo

Learning Kendo UI Web Development by John Adams

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Using AutoComplete with MVC through Models

We can take this one step further and transform our code into Razor syntax with MVC. First, create a controller action method to return data from the server.

public ActionResult AutoCompletePage()
{
  var repository = new SampleRepository();
  var data = repository.GetStatesAndTerritories();
  return View(data);
}

Next, open AutoCompletePage.cshtml and delete everything in it after the <h2> tag. At the top of the file, we need to add a declaration so that this View page becomes strongly-typed to our new model class StateTerritory.cs.

@model IEnumerable<LearningKendoUIWeb.Models.StateTerritory>

Now add this code that utilizes the HTML helper class and the Kendo extension methods.

<h2>AutoCompletePage</h2> @(Html.Kendo().AutoComplete() ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required