From the course: Learning ASP.NET

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Web API with Ajax

Web API with Ajax

From the course: Learning ASP.NET

Start my 1-month free trial

Web API with Ajax

- We've just built a restful web API, to get student data. Now let's focus on how to call it from a MVC client application. We'll use AJAX to call the API and then we'll display the results in a student view. Let's start off by adding a new controller to the MVC application. Right-click on controllers, add controller and pick the MVC controller empty option. And name it student controller. The scaffolding added an index action that returns a view, which is just what we need to show the student list. Let's right-click index and select Add View. Keep the defaults and click add. And here's our new index view, which was just added under the student folder. There's some basic content already included here, but I'll replace it with the content in the course index view. Just to start off with the right HTML, let's change this heading on line 12 from courses to students and underneath add a div tag, with an id of students. Underneath the article tag, go ahead and add a script tag. We'll use…

Contents