• .NET Developer Tools DevTools

    UI controls for ASP.NET AJAX, MVC, WPF,
    Silverlight, Windows 8 and Windows Phone

  • Hybrid Mobile Development Icenium

    Cross-platform Mobile Development Tool
    with cloud-based architecture

  • HTML5 / JavaScript Development Kendo UI

    Everything you need to build sites and
    mobile apps with JavaScript and HTML5

  • Testing Tools TestStudio

    One easy tool for Functional, Performance,
    Load and Mobile software testing

  • Web Presence Platform Sitefinity CMS

    Everything for your online business - content
    management, ecommerce, emarketing

  • Agile Project Management TeamPulse

    Simple and intuitive project management
    and collaboration software

Contact us

We are here for you.
  • usa+1‒888‒365‒2779
  • uk+44‒20‒7291‒0580
  • bg+359‒2‒8099850
  • de+49‒89‒2441642‒70
  • au+61‒2‒8090‒1465
  • emailsales@telerik.com
Your account Access to your products, updates and support
Telerik Product Families
  • Your Account
    Your Account
    Log in
  • ABOUT US

    About Telerik

    • Company
    • Press Center
    • Customers
    • Community
    • Careers
    • Contacts
Kendo UI - The way of HTML5
Products ▼
Kendo UI Web Kendo UI Mobile Kendo UI DataViz Server Side Wrappers
Demos Purchase Download
Blogs Documentation
Support ▼
Premium Forums StackOverflow Forums
Resources ▼

Featured Resource

Kendo UI Dojo


Blogs Code Library Demos Documentation FAQ Testing
Premium Forums Roadmap User Voice Videos Webinars More Resources
Contact Us Search
 

Blogs

Hello Services / WebAPI, REST, JSON and AJAX

Friday, May 11, 2012 by Kendo UI Team Blog | Comments 33

This is the second module in the ongoing course HTML5 Development For ASP.NET Developers.

This module will cover how to create a RESTful service with ASP.NET WebAPI, and how to consume that service in JSON format with jQuery. There is also a very quick primer on the concept of REST and JSON, as well as a good look at using the IE F12 Developer Tools to debug your application.

All code used in this module can be downloaded from the course GitHub project. Feel free to download the finished product, or follow along with the screencast or written content.

Screencast

Written Summary

In this tutorial, you will be building a sample application which displays data from a SQL Server table using AJAX to fetch the data from a WebAPI service. You will also add CRUD abilities to both the UI and the service while learning how to stay RESTful with your service implementation.

Quick Primer On REST and JSON

REST stands for Representational State Transfer. It’s a pattern for developing services which lets the HTTP requests describe what sort of action should be done, what format the data should be in and allows the server to indicate success or failure using HTTP codes. Using this strategy, it is easy to construct very predictable URL’s for web services so that consuming them becomes much easier. There is much more to REST than that short explanation, but this tutorial will try to stay as RESTful as possible.

JSON is an acronym that stands for JavaScript Object Notation. This is a way of serializing data and objects into a very simple and easy to understand string representation. This format is easily consumable not only buy JavaScript, but is also much easier for humans to read and debug.

Create The Sample Application

Open Visual Studio. Select File / New Project and select the ASP.NET Web Application template. Name the application HelloServices.

file-new-project

Open the Default.aspx page and delete all the content.

Project Structure

Before proceeding with this project, create some structure for the application to keep it organized. Create a folder called Data directly under the main project which will hold the data access layer. Create a second folder called Controllers which will hold the WebAPI service that will be created in this tutorial.

data-controllers

Create A Data Access Layer

For this tutorial, the Northwind Database will be used. Additionally, LINQ To SQL will be used as the Data Access layer given it’s simplicity and ease of use. If you have not already installed the Northwind Database, you should do that before proceeding.

Right-click the Data folder and select Add New Item. When the dialogue comes up, select a new LINQ To SQL Classes. Give the .dbml file the name NorthwindContext.dbml. Click Add. This will bring up the LINQ To SQL designer surface. Open the Servers Explorer window either from the left-hand side, or from the View menu. Expand the Northwind database and expand Tables. Drag the Employees table onto the design surface. Save the file.

add-linq-to-sql

linq-to-sql-table-added

Install NuGet Packages

Install WebAPI

Before the service to return the data from the database can be created, WebAPI must be installed from NuGet.

Right click the project and select Add Library Package Reference. When the dialogue comes up, click the online tab on the left-hand side and enter “aspnetwebapi” in the search box. Select AspNetWebApi from the search result and click the “install” button. Accept the package dependencies and install those as well.

nuget-aspnetwebapi

Install jQuery

Enter “jquery” in the search box. Select the jQuery result and select “install”.

install-jquery

Close the Add Library Package Reference dialogue.

Create WebAPI Service

In order to create the WebAPI Service, an empty class is needed. Right-click the Controllers folder and select Add and then Class. Name the class EmployeesController.cs.

employees-controller

In order to designate the EmployeesControllers.cs class that was just added as a WebAPI controller that will respond to requests, inherit from the ApiController class. If ApiController is not recognized for you, hover over the word until you get the context menu. This will give you the option to include System.Web.Http. Optionally, you can achieve the same result by click Alt+Shift+F10, which will bring up the same context menu.

employee-contoller-class-inherit

This class will contain methods that can be invoked from the web service that is being created. This service represents the Employees table in the Northwind Database. This is the table that will be used in this tutorial for data.

A typical RESTful endpoint will respond to the following HTTP verbs:

  1. GET - Used when a browser is requesting data from the server
  2. PUT - Typically used when updating an item
  3. POST - Typically used when creating a new item
  4. DELETE - Used when deleting an item

To start with, create a get method. This method will return all of the data in the Employees table in the Northwind Database. Name the method Get(). The method should return a list of Data.Employee objects. The Data.Employee object is created automatically for you by LINQ To SQL when the Employees table was added to the LINQ To SQL designer surface.

Create an instance of the Data.NorthwindDataContext at the top of the file and name it _context. This is the object that will be used to query the database.

Inside of the Get() method, write a simple LINQ query to retrieve all of the employees from the Employees table.

LINQ Query To Select All Employees

public List<Data.Employee> Get() {

    var employees = from e in _context.Employees
                    select e;

    return employees.ToList();

}

 

Since WebAPI operates on convention over configuration, simply naming this method Get() is enough to designate as the method that will respond to an HTTP GET.

return-linq-object

You can override this convention by specifying the verb you want a method to respond to by decorating the method with the correct attribute (i.e. [HttpPut]).

Setup Routing

Before WebAPI can return return results via a URL, a route needs to be setup so that the application knows to map a specific route back to the EmployeesController.cs file in the Controllers folder.

Open the Global.asax file. Under the Application_Start method, add the following code.

Setup Routing For WebAPI

void Application_Start(object sender, EventArgs e) {

    // intialize the default routing configuration
    RouteTable.Routes.MapHttpRoute(
        name: “DefaultApi”,
        routeTemplate: “api/{controller}/{id}”,
        defaults: new { id = System.Web.Http.RouteParameter.Optional });
}

 

This block initializes routing for WebAPI.  This is how it knows to route URL’s to certain controllers.  In this case, the default route says that anything coming after /api on the root should be routed to a controller.  It’s also passing an optional id parameter on the end of the url.  If the id is passed, it will be handed off to the proper method.  If nothing is passed, it will be ignored.

This means that the route for the EmployeesController will be something like http://localhost:3593/api/employees.

Test The Application

Press F5 to build and run the application.  You will notice that the application throws an error that is somewhat obscure.  If you inspect the details of that error, it will tell you that it cannot serialize the LINQ To SQL object.

serialization-error

This is because .NET cannot serialize the LINQ To SQL object that is being returned by the Get() method in the EmployeesController.cs file. LINQ To SQL Objects are rather complex and contain far more information than what is actually needed by the UI, which is the raw data.

Add A Model

To get the raw data out of the LINQ To SQL objects and into a format that .NET can easily serialize, you will create a model object which will represent one row in the Employees table. This model will have properties that mirror the columns in the Employees table. For the sake of brevity, you will only add 3 properties to the model.

Right-click the project in Visual Studio and select Add Folder. Name this folder Models. Right-click the Models folder and select Add then Class. Optionally, you can achieve the same effect by pressing Shift+Alt+C. Name this class Employee.

In the Employee class which is now in the Models folder, add three properties. One for the employee id, first name, and last name.

Employee Model Object

public class Employee {

    public int Id { get; set; }
    public string FirstName { get; set; }
    public string LastName { get; set; }

}

 

employee-model

Open up the EmployeesController.cs file in the Controllers folder. Alter the Get() method to return a list of Model.Employee objects instead of a list of Data.Employee objects. Also alter the LINQ To SQL Query so that it selects a new Employee model object for each row returned from the database.

Return A List Of Employee Model Objects

public List<Model.Employees><models.employee> Get() {

    // select a new model object for each row in the
    // linq query result
    var employees = from e in _context.Employees
                    select new Models.Employee {
                        Id = e.EmployeeID,
                        FirstName = e.FirstName,
                        LastName = e.LastName
                    };

    return employees.ToList();

}
</models.employee>

 

web-get

Test The Application

Press F5 to run the application again. Navigate to the api/employees URL. Notice that WebAPI returns the records from the Northwind Employees table in XML format.  IE will try to download the file, but other browsers such as Chrome will display the results.

employees-xml

Getting JSON Data With AJAX

Now that data is being returned by the service, it is possible to use jQuery to call that service with AJAX and get the results in JSON format instead of XML. Once the data has been retrieved as JSON, it is much easier to work with it and create a user interface.

For this demonstration, you will be retrieving the list of employees and displaying each employee in an HTML table row.

Add jQuery To The Project

Open the Site.Master file and drag the jquery.min file over to the page just below the Site.css link tag in the head of the page. At the time of this writing, the current version of jQuery is jquery-1.7.2.min.js.

add-jquery-to-master-page

Open up the Default.aspx file. Create an HTML table element with the id “employees”.

Create An HTML Table Element

<table id="employees"></table>

Below the table element that you just created, but before the closing content tag, open a new script block.

Open A New Script Block

<table id="employees"></table>

<script>
	
    // jquery ajax code will go here
	
</script>

 

Inside the script block, create a jQuery Document Ready function. This is the function that executes when the entire page has loaded, including all HTML, CSS and included JavaScript files.

Inside the Document Read function, select the HTML table with the id employees from the DOM and assign it to a variable call $employees for later use. It is considered a good practice by some to prefix variables containing jQuery objects with a $ so that the developer will know that the variable represents a jQuery wrapped object when he/she sees it later down in the code. The table is selected by it’s ID using the jQuery ID Selector (“#” sign).

Select Table When The Document Is Ready

<table id="employees"></table>

<script>
	
    // document ready function
    $(function() {
		
	// select the employees table from the page and
	// store it in a variable for later use.
	var $employees = $("#employees");
    });

</script>

 

AJAX

The term AJAX is an acronym that stands for “Asynchronous JavaScript And XML”. However, it has come to take on a much broader and less specific meaning. AJAX generally refers to the action of making a request to the server in the background and receiving a result. This is different from the typical browser request/response communication in that it happens without any visual indication that anything has taken place. It is absolutely silent unless the UI is built to show background requests. Additionally, XML is rarely used anymore for AJAX operations. It is most common now to use JSON, which is an incredibly simple form of serialization that is very easy to manipulate with JavaScript. WebAPI has fantastic support for rendering JSON with the new System.Json library.

One of the things that makes jQuery so desirable, is that it makes ajax very trivial for a developer to implement. To make an AJAX call to the WebAPI Employee service, use the jQuery .ajax() function. This function takes an object that contains the parameters for configuring the AJAX request. For the request to the api/employees endpoint, the configuration object will need the url, contentType, and success options specified.

  • url - this option will be specified as the string “api/employees”. This URL is a relative path, so there is no need to specify the full url.
  • contentType - since it is much easier to work with JSON, the ajax request needs to specify that the data should be in JSON format. This is done by setting the HTTP Header content type to “application/json”. When using jQuery, this is done simply by setting contentType to “json”
  • success - this is the function that will be called when the server returns a response to the ajax call. The function takes in a data parameter, which will hold the JSON response returned from the employees web service.

Make An AJAX Call For The Employees Data In JSON Format

<table id="employees"></table>

<script>
	
    // document ready function
    $(function() {
		
	// select the employees table from the page and
	// store it in a variable for later use.
	var $employees = $("#employees");
		
	// make an ajax call to the employees WebAPI service
	// to retrieve a JSON response of all the employees
	$.ajax({
	    // the url to the service
	    url: "api/employees",
	    // the format that the data should be in when
	    // it is returned
	    contentType: "json",
	    // the function that executes when the server
	    // responds to this ajax request successfully
	    success: function(data) {
				
		// put the JSON response in the employees table
				
	    }
			
	});
    });
	
</script>

 

In order to put the data returned into the page, it will be necessary to iterate over the results returned by the server. This is done using the jQuery .each() function. As each item is iterated over, a new row is added to the employees HTML table by using the jQuery append() method. The table variable is used instead of selecting the table each time in the loop. Selecting an item once from the DOM and referencing it in a variable is better for performance and cuts down on code clutter.

Make An AJAX Call For The Employees Data In JSON Format

<table id="employees"></table>

<script>
	
    // document ready function
    $(function() {
	
	// select the employees table from the page and
	// store it in a variable for later use.
	var $employees = $("#employees");
		
	// make an ajax call to the employees WebAPI service
	// to retrieve a JSON response of all the employees
	$.ajax({
	    // the url to the service
	    url: "api/employees",
	    // the format that the data should be in when
	    // it is returned
	    contentType: "json",
	    // the function that executes when the server
	    // responds to this ajax request successfully
	    success: function(data) {
				
	        // iterate over the data items returned from the server
	        // the index variable is the position in the colleciton.
	        // the item variable is the item itself
	        $.each(data, function(index, item){
				
		    // append the first and last name to the table
		    $employees.append("<tr><td>" + item.FirstName + "</td>" +
				          "<td>" + item.LastName + "</td>");
					
	        });
				
	      }
			
	});
    });
	
</script>

 

Test The Application

Press F5 to run the application, or if your app is still running, simply save the file and refresh the page or point the page at the Default.aspx url. Since all the changes were made in JavaScript, it’s not necessary to stop and start the application.

Notice that the application shows the employees in a list. Press F12 to open the developer tools. Click on the network tab and click the “Start Capturing” button. Refresh the page. Notice the request that is made to api/employees. Double-click on the request. Notice that the Content-Type is set to JSON.

f12-content-type-json

Select the Response body tab. Inspect the JSON response returned from the server.

f12-response-body-json

Enable Deleting Of Employees

Switch back to Visual Studio and the Default.aspx page. In order to add the ability to delete employees from the UI, its necessary to add a button out to the right-hand side of each row. This could be done by adding more HTML inside the .each() loop. However, this is already a bit messy. There is HTML in the JavaScript and adding to this would make it worse. Its generally best practice not to include HTML inside the JavaScript this way.

Templating

In order to clean this up and make it better, its a good idea to use a concept called templating. This is simply the idea of having a single table row which is created once and then copied for each element in the dataset and appended to the table. There are many forms of templating and some libraries that make this much simpler. This will be explored in more detail in later modules.

For this example, a very rudimentary form of manual templating will be demonstrated. The idea here is to add a block of HTML that is invisible on the page, but can be used to dynamically create HTML elements. Specifically for this example, a table row is needed. This implementation involves adding a div with an id of templates right after the closing script block. The style on this div will be set to display: none. This means that this div and all its content will not be displayed on the page. Inside of this div, create a table. Create a single table row definition with a column for first name, a column for the last name, and a column for the delete button that contains a button. These elements will have classes and not id’s since they will be used over and over again.

Create A Block Of Template HTML

<table id="employees"></table>

<script>
	
    // document ready function
    $(function() {
		
	// select the employees table from the page and
	// store it in a variable for later use.
	var $employees = $("#employees");
		
	// make an ajax call to the employees WebAPI service
	// to retrieve a JSON response of all the employees
	$.ajax({
	    // the url to the service
	    url: "api/employees",
	    // the format that the data should be in when
	    // it is returned
	    contentType: "json",
	    // the function that executes when the server
	    // responds to this ajax request successfully
	    success: function(data) {
				
		// iterate over the data items returned from the server
		// the index variable is the position in the collection.
		// the item variable is the item itself
		$.each(data, function(index, item){
				
			// append the first and last name to the table
			$employees.append("<tr><td>" + item.FirstName + "</td>" +
					      "<td>" + item.LastName + "</td>");
					
		});
				
	    }
			
	  });	
     });
 </script>
<div id="templates" style="display: none">        
    <table>            
	<tr class="row-template">                
	    <td class="firstName" style="width: 100px;"></td>
	    <td class="lastName" style="width: 100px;"></td>
	    <td>
	        <input type="button" value="X" class="delete" />
	    </td>
	</tr>
    </table>     
</div>

 

Inside of the each() loop, select the templates div by its id. Then use the jQuery .find() method to select the row by it’s class. This will find the item(s) in the children of the templates div with the specified selector. Once the table row is selected, call the jQuery clone() method. This will create a new object of the same type that was just selected (a table row), and store it in the variable.

This is called “Chaining” in jQuery. This is when methods are called on methods because each method returns an object, allowing the developer to continue to call methods on the same line. Once the row template has been created, find the first and last name columns and set their .html() with the first and last name from the returned JSON data. Then select the button by it’s class and add a click event.

Inside of the click event, create another ajax() method. The URL will be the same as the first ajax() method with the exception that the current item id is appended onto the end. This creates a RESTful URL. The type should be set to delete. In the success function, simply remove the item from the page by calling the jQuery .remove() function. This will reflect the database change in the UI.

Lastly, right before the closing bracket for the each() loop, append the row to the table.

Create A Block Of Template HTML

<table id="employees"></table>

<script>
	
    // document ready function
    $(function() {
		
	// select the employees table from the page and
	// store it in a variable for later use.
	var $employees = $("#employees");
	
	// make an ajax call to the employees WebAPI service
	// to retrieve a JSON response of all the employees
	$.ajax({
	    // the url to the service
	    url: "api/employees",
	    // the format that the data should be in when
	    // it is returned
	    contentType: "json",
	    // the function that executes when the server
	    // responds to this ajax request successfully
	    success: function(data) {
			
		// iterate over the data items returned from the server
		// the index variable is the position in the colleciton.
		// the item variable is the item itself
		$.each(data, function(index, item){
			
		    // create a row template
		    var $row = $("#templates").find(".row-template").clone();
					
		    // set the first and last name column text for the row
		    $row.find(".firstName").html(item.FirstName);
		    $row.find(".lastName").html(item.LastName);
					
		    // find the button and set its click event
		    $row.find(".delete").click(function() {
					
		    // call the delete method on the employees service
		    $.ajax({
		        // append the current employee id onto the url
		        url: "api/employees/" + item.Id,
		        // set the request type to be a DELETE
		        type: "DELETE",
		        // remove the row on a success response from the server
		        success: function() {
								
		            $row.remove();
								
		        }  
		    });
						
	        });
					
	    // append the row to the table
	    $employees.append($row);
					
        });
				
      }
			
    });
});
	
</script>	
<div id="templates" style="display: none">        
    <table>            
	<tr class="row-template">                
	    <td class="firstName" style="width: 100px;"></td>
	    <td class="lastName" style="width: 100px;"></td>
	    <td>
	        <input type="button" value="X" class="delete" />
	    </td>
	</tr>
    </table>     
</div>
	

Run The Application

Press F5 to run the application. Open the Developer Tools in IE by pressing F12. Switch to the network tab and click Start Capturing. Notice that when the delete button is clicked, an AJAX request is fired to the server with a method of DELETE. The server is currently returning a 404, because the DELETE method has not yet been created in the service.

delete-not-implemented-404

Add A Delete Method To The Employees Service

Switch back to Visual Studio and stop the application. Open up the EmployeesController.cs file in the Controllers folder. Create a void method underneath the Get() method called Delete() which takes in an id parameter of type int.

Create A Delete Method

public void Delete(int id) {

    // code to delete employee by id goes here

}

Inside of the Delete() method, select the employee to delete by it’s id from the LINQ to SQL context. Delete the employee and submit the changes using LINQ To SQL.  The id parameter is passed along by the default routing that was setup in the Global.asax.  Since the method is named Delete(), it will respond to an HTTP DELETE verb.

Delete The Employee With LINQ To SQL

public void Delete(int id) {

    // select the employee from the database by its id
    var employeeToDelete = (from e in _context.Employees
                            where e.EmployeeID == id
                            select e).FirstOrDefault();

    // delete the employee from the context
    _context.Employees.DeleteOnSubmit(employeeToDelete);

    // submit the changes
    _context.SubmitChanges();

}

Add yourself as an employee in the Northwind Employees table by providing just your last and first name. The other employees cannot be deleted due to existing relationships in other tables.

Run The Application

Press F5 to run the application. Press F12 to open the Developer Tools. Switch to the Network tab and click Start Capturing. Click on the delete button next to the name you added to the database. Notice that the delete AJAX request happens and a 200 is returned from the server. This means that everything has happened OK and the item has been deleted from the database. Also notice that your name was removed from the page by jQuery.

finally

Further Reading / Resources

WebAPI is a maturing library and is baked into the next official release of MVC 4. For now, the following screencasts should help you become quite familiar with using WebAPI in MVC 4.

WebAPI With MVC 4 Screencast Series

The completed application used in this project is available on the course GitHub site.

About the Author
Burke Holland is a web developer living in Nashville, TN. He enjoys working with and meeting developers who are building mobile apps with jQuery / HTML5 and loves to hack on social API's. Burke works for Telerik as a Developer Evangelist focusing on Kendo UI. Burke is @burkeholland on Twitter.

33 Comments

  1. 1 Vesselin Obreshkov 11 May 2012
    Cool stuff. We're building an app using WebAPI. Needs some work but it's pretty cool overall. It can work very well with Kendo UI once you figure out your paging, sorting and filtering.
  2. 2 Burke 14 May 2012
    @Vesselin

    Yep, and I'll be touching on that in later modules because I know that's a sticking point for a lot of people.  We'll do paging, sorting, filtering - the whole 9 all on the server.  We'll even virtualize some data so we can get rid of paging all together!
  3. 3 Nello 14 May 2012
    Hi,
    first I think your tutorial is very good but I followed every instructions without any errors and I cant have the xml results when I go to the url ; api/casesLoads

    Here is what I get :

    <string>No type was found that matches the controller named 'casesLoad'.</string>

    I'm using an other database also a table called caseLoad maybe it's where the problem come from ?
  4. 4 Nello 14 May 2012
    Nevermind I was wrong about my controller name...
  5. 5 Nello 14 May 2012
    Just one other thing, I have got my Default.aspx which display correctly the table, I'd like to know how i can use the json response using it as a dataSource for a Kendo application ?

    In fact how can i get the response from the request ?
  6. 6 Ben Hayat 15 May 2012
    Burke, one very important aspect of building LoB apps, especially over internet is security, authentication and authorization. ASP.Net has a nice server side model that you can use to secure your resources and the framework provides lots of properties and methods to use on the client side to control the page and what can be accessed. Silverlight tapped into this backend feature and also provided rich client side functionality via WCF RIA services.

    My question and request is, building LoB apps using WebApi middle tier and ClientUI, how are we going to have a full security system that is currently available to ASP.Net webforms?

    It would be great to have a full session on this subject, because without full authentication & authorization, no application will have any value.
    Thanks!
    ..Ben
  7. 7 MIke 15 May 2012
    I too am very interested in security, authentication, and authorization in LoB apps, so I'm anxious to see your response to Ben Hayat's question.

    Thanks,

    Mike 
  8. 8 zaib 17 May 2012
    good example
  9. 9 Mark Spelling 17 May 2012
    "consumable not only buy JavaScript"

    should read:

    "consumable not only by JavaScript"
  10. 10 Burke 17 May 2012
    @Nello

    In the coming modules, I will hook Kendo UI up to this WebAPI service.  Stay tuned!
  11. 11 Siva K 18 May 2012
    Good question from Ben. I am also interested to see answer!
  12. 12 Rob 18 May 2012
    for the delete method, i find that $row refers to the last row added, and not the row that the delete is comming from. This causes the last row to be removed from the table and not the row that was deleted. Any ideas as to how to get the actual row you are removing?
  13. 13 Siva K 18 May 2012
    Good question from Ben. I am also interested to see answer!
  14. 14 Rob 18 May 2012
    Re the delete.. My mistake. when i got the $row forgot to type var first.
    e.g.
    var $row = $("#template").find(".row-template").clone(); 

    the var was missing.
  15. 15 Rhett 18 May 2012
    this was ultra helpful... thanks!  Can you do a jsonP example?
  16. 16 Dharmendra Mistry 19 May 2012
    RouteTable.Routes.MapHttpRoute not found in 
    Globle.asax 
    
    I tried to add MapHttpRoute in Applicaion_Start by adding System.Web.Routing Namespace. but not get it working. I created Asp.net web application and added AspNetWebApi by NuGet. I follow the same steps described above.
    
    Thanks in advanced.
  17. 17 Gerard Mark 21 May 2012


    Dharmendra 

    You should import the "System.Web.Routing" namespace

  18. 18 Jalpesh vadgama 23 May 2012
    Nice work,

    Regards,
    Jalpesh
    http://www.dotnetjalps.com
  19. 19 Burke 23 May 2012
    @Ben

    Sorry I have been out for a while traveling and I'm catching up!  In regards to securing WebAPI Services, check out the site http://leastprivilege.com/.  There is a lot there in terms of implementing tokenized authentication for services.
  20. 20 Simon Murrell 22 Jun 2012
    RouteTable.Routes.MapHttpRoute is not available. I imported the System.Web.Routing. The ASPNetWebApi (v4.0.20505.0) is a different version though. It does however have a method called MapPageRoute.
  21. 21 cheezy_dev 27 Jun 2012
    hi, I wanted to know if there is a sample that interacts with server side MVC, web api controller - Haven't come across samples.

    Thanks.
  22. 22 Tushar Solanki 16 Jul 2012
    Dharmendra Mistry: TRY THIS

    using System.Web.Http;
  23. 23 Dave 18 Jul 2012
    Great post.  Is there also an example on how to bind the data from the ApiController to the Kendo UI controls, such as the Grid?
  24. 24 Mili 23 Jul 2012
    Hi,
    This is  a very good example.
    I need to know how to implement Create CURD of Kendo UI GRID using this service.
    Thanx
  25. 25 Burke 23 Jul 2012
    @Dave @Mili

    Check out the next module in the series Hello Kendo UI.  We are going to be doing a lot of CRUD!
  26. 26 Mili 24 Jul 2012
    Hi Dave,

    Thanx for your reply.

    But i need to know how to implement PUT and POST.

    Thank You.
  27. 27 Mili 24 Jul 2012
    So sorry....
    Above comment is for Burke .
    ;)
  28. 28 Denis 01 Aug 2012
    Thanks nice video
  29. 29 Dude 14 Aug 2012
    Thank you !
  30. 30 xp li 06 Oct 2012
    Wonderful post!! Thx!
  31. 31 Clay Shannon 16 Oct 2012
    Is something newer than XP and VS 2010 needed? I followed along up to the point of: "
    EmployeesController : ApiController 

    and ApiController is not recognized. Neither is, when I add it:

    using System.Web.Http;
    
  32. 32 Matt 31 Oct 2012
    I followed your video and downloaded the source code form GitHub.  But when I try to run the application as is, I get the following error: Method 'get_Handler' in type 'System.Web.Http.WebHost.Routing.HostedHttpRoute' from assembly 'System.Web.Http.WebHost, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' does not have an implementation.
  33. 33 NV 30 Nov 2012
    Hi,
    I was trying to get the the list of employees with parameters.
    In my exmaple i'm using a datepicker to select a date and use this selected date as a parameter to the controller.
    Is it possible?

Comment

  1. Click to add

  2. Click to add

  3. Click to add

  4.    
     
    •  
    •  
    •  
    •  
    •  
    •  
    •  
    •  
    •  
    •  
    •  
    •  
     
      
       
Blogs feed
Categories

  • Tutorials (26)
  • Release (33)
  • Browsers (7)
  • Extensions (3)
  • Tip of the Week (10)
  • Videos (5)
  • Concepts and Theory (13)
  • Misc. (25)
  • Framework Constructs (6)
  • Mobile (6)
  • UI Widgets (5)
  • Blogs (1)
Archive
  • 2013 May (7)
  • 2013 April (10)
  • 2013 March (9)
  • 2013 February (12)
  • 2013 January (10)
  • 2012 December (9)
  • 2012 November (11)
  • 2012 October (6)
  • 2012 September (7)
  • 2012 August (8)
  • 2012 July (10)
  • 2012 June (8)
  • 2012 May (10)
  • 2012 April (7)
  • 2012 March (13)
  • 2012 February (10)
  • 2012 January (6)
  • 2011 December (10)
  • 2011 November (4)
  • 2011 October (6)
  • 2011 September (5)
  • 2011 August (9)
Home Web Mobile DataViz Server Wrappers Whitepapers Surveys Chrome Icenium Contact Us

Kendo UI framework is developed by Telerik - a leading provider of UI components for web, desktop and mobile applications. Trusted by over 100,000 customers worldwide for our devotion to quality and industry-best technical support, Telerik helps professionals maximize their productivity and "deliver more than expected" every day.

kendoui - powered by html5, css3 & jquery
get social
  • Twitter
  • Facebook
  • Google plus
  • RSS
Privacy Policy | Branding Guidelines
Powered by Sitefinity CMS

Copyright © 2011 - 2013 Telerik Inc. All rights reserved.