Introduction
Microsoft WebMatrix provides an easy way to get started with web development, and together with new Razor syntax for ASP.NET Web Pages it includes everything you need to get your web site up, running and integrated with many other sites and networks, in a short period of time. The WebMatrix helpers are designed to make your life easier when creating web sites. They provide you a simple and consistent way of performing common web development tasks that otherwise would require a great deal of custom coding. With a few lines of code you should be able to secure your web site using membership, store information in Windows Azure Storage, integrate your site with Facebook, among others things.
The OData helper allows you to easily retrieve and update data from any service that expose its data using the OData Protocol. It does not require that you configure any specific client or create any custom class; by pointing the helper to the correct URL, you can have all the data you need ready to be displayed using the Razor syntax.
Getting Started in 60 Seconds
The helper consists mainly of a Microsoft.Web.Helpers.OData.dll library located into the Bin folder of your WebMatrix site. To use the OData helper follow these steps:
- In any WebMatrix page, add the following highlighted code. This will query the NetFlix OData service:
@{
var result = OData.Get("http://odata.netflix.com/Catalog/Genres('Horror')/Titles","$orderby=AverageRating desc&$top=5");
var grid = new WebGrid(result);
}
<!DOCTYPE html>
<html>
...
<body>
@grid.GetHtml()
...
</body>
</html> - For more examples of queries check out the helper samples!
Running the Samples
The helper package includes a set of WebMatrix pages where you can see the helper in action. To run them follow these steps:
- In Microsoft WebMatrix, under the Files workspace, right-click the ODataHelper\SampleApp folder and select 'Launch in browser'. This will open the sample web site with WebMatrix.
- Play with the samples!
More Info
To explore the helper's implementation you can download its source code from the OData Helper CodePlex project; it includes unit tests for the helpers methods.
Learn more on WebMatrix, ASP.NET Web Pages and the Razor Syntax with the WebMatrix tutorials.