Click here to Skip to main content
11,813,974 members (35,561 online)
Click here to Skip to main content

Consuming WebAPI Using jQuery

, 4 Sep 2012 CPOL 15.9K 10
Rate this:
Please Sign up or sign in to vote.


ASP.NET Web API is a framework for building and consuming HTTP services that can be reached by a broad range of clients including browsers and mobile devices. In this sample I will show how you can build web APIs that support browser clients and can be easily called using jQuery.


  • Visual Studio 2010 SP1, Visual Web Developer 2010 SP1 or Visual Studio 2012

Getting Started

The following simple steps show you how to create a WebAPI and call that WebAPI using a JSON object.

Step 1

Open Visual Studio 2010 and under Web select “ASP.NET MVC4 Web Application” and name it “HelloWebAPI” and click OK.


Step 2

After clicking the OK button the New “ASP.NET MVC4 Project” window will open, in that select “WebAPI” and click OK.


Step 3

To create a new Model Class, go-to Solution Explorer (F4), right click on Model->Add->Class and name the class “Product” and paste the following code.


Step 4

To create a new controller right-click on the Controller -> Add -> Controller and the “Add Controller” dialog will open, name the Controller “ProductsController”, then in Scaffolding options template, select “Empty API Controller” and click the Add button.


Step 5

In “ProductsController.cs”, paste the following code:


Step 6

In Solution Explorer, expand the Views folder and open Index.cshtml, replace with the following code.


Step 7

Click on Start debugging (F5), the following result will show in the browser.



This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Ravindra T C
Software Developer L&T IES Mysore
India India
I'm a software developer. I spent most of the time in learning new technologies. I've a keen interest in client-side technologies especially JavaScript and Jquery it is the most beautiful language ever seen.

I like sharing my knowledge and written some non-popular articles. I believe in quality and standards but blames myself for lagging them.

I believe in small things and they makes me happy!

You may also be interested in...

Comments and Discussions

GeneralMy vote of 3 Pin
HariPrasad katakam8-Jul-13 3:32
memberHariPrasad katakam8-Jul-13 3:32 
GeneralMy vote of 1 Pin
Dmitry Gonchar2-Mar-13 17:34
memberDmitry Gonchar2-Mar-13 17:34 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.151002.1 | Last Updated 4 Sep 2012
Article Copyright 2012 by Ravindra T C
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid