.NET Zone is brought to you in partnership with:

Daniel Mohl is a professional software engineer/architect whose interests include understanding the intricacies of various programming languages, enterprise application architecture, and how to bridge the gap between business and technology. He works with F#, C#, CoffeeScript, JavaScript, Erlang, ASP.NET MVC, WPF, WCF, Silverlight, WP7, SQL Server, etc. He is a F# MVP, C# Insider, F# Insider, blogger, speaker, and event organizer. You can follow him on twitter at www.twitter.com/dmohl. Daniel is a DZone MVB and is not an employee of DZone and has posted 30 posts at DZone. You can read more from them at their website. View Full User Profile

A Single Page App With Backbone.js, ASP.NET Web API, and F#

09.27.2012
| 5953 views |
  • submit to reddit
In this post, I introduce a simple example of a single page application built with Backbone.js, ASP.NET Web API, F#, and more. The example is an overly simple contacts app that allows you to view contacts and create new ones. It uses the Foundation 3 framework for styling and responsive design.

Here's a screenshot of the simple contact list view:







Solution Organization:

The C# project contains the following:
  • A single Index.cshtml file. 
  • All images, CSS, and JavaScript.
  • A "Templates" folder that contains 2 .htm files that hold the markup for each view. The templating feature of underscore.js is used to allow placeholders in the templates to be replaced with the desired data.
The heart of the client-side code is broken into 3 folders within the Scripts folder of the C# project:
  • The "app" folder contains a main.js, a utility.js, and a file containing route definitions using Backbone.Router.
  • The "models" folder contains the Backbone models and collections.
  • The "views" folder contains Backbone views.

The F# project contains the following:
  • ASP.NET MVC and Web API routes.
  • Definitions of JS and CSS bundles.
  • ASP.NET MVC and Web API Controllers.
  • A Model class.
Getting the Code:

You can find the full source at https://github.com/dmohl/FsWebSpa-Backbone.
Published at DZone with permission of Daniel Mohl, author and DZone MVB. (source)

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)