Saturday, December 8, 2012

Using the New ASP.NET MVC 4 Template in MonoDevelop

In my last post, I showed an example of an ASP.NET MVC 4 application built in MonoDevelop. Since that time, an ASP.NET MVC 4 project template has been created for MonoDevelop that makes it very easy to create a similar app.

Here are the steps for using this template:

1. To get started, install version 3.0.2+ of Mono, the latest version of MonoDevelop, and the F# Language Binding (through the MonoDevelop Add-in Manager). If you've already installed each of these, make sure that the F# Language Binding version is 3.2.8+.

2. Create a new solution (File | New | Solution) and select F# | ASP.NET | F# ASP.NET MVC 4 (Razor) as shown here:
3. Add the desired solution name, click OK, and your done.

Well that was easy, but where do you go from here? Let's walk through a simple example of creating an app for keeping track of contacts. The end result will be similar to the screenshot shown in my post entitled A Single Page App with Backbone.js, ASP.NET Web API, and F#.

1. I've already followed the previous steps to create an ASP.NET MVC 4 application in MonoDevelop called MyContacts. To quickly add a decent look to the app, I'll use the responsive front-end framework from ZURB called Foundation. All that I really need is the CSS, so I add the foundation.min.css file to the Content folder in the project. I also add an app.css file for any custom styles that are needed. The content of the app.css file is shown below:

2. I can now reference these CSS files in _Layout.cshtml. The modified file looks like this:

3. Now I modify the Index.cshtml file in the Home folder so that it will display the list of contacts. The result is shown below:

4. Lastly we make a few modifications to the HomeController. Here's the code:

5. That's it. We can now launch the site and see the following:






Monday, November 19, 2012

F#, ASP.NET MVC, and MonoDevelop

I often talk about creating web solutions with F# in Visual Studio. Today I'm going to switch things up a little and provide an example of an ASP.NET MVC solution built with MonoDevelop.

MonoDevelop:

For those that aren't familiar with MonoDevelop, it's an open source IDE that runs on a variety of operating systems including Windows, Mac OSX, and Linux. MonoDevelop works hand-in-hand with Mono, which is "an open source, cross-platform, implementation of C# and the CLR that is binary compatible with Microsoft.NET". This means that you can write the same .NET code that you would in Visual Studio and run it on any of the most popular operating systems.

Getting Setup for F# Development:

There are a number of resources out there that talk about how to get your environment setup with MonoDevelop and F#. Here's a quick set of steps:

1. Install MonoDevelop, .NET or Mono, and GTK# from http://monodevelop.com/Download.

2. Launch MonoDevelop and open the Add-in Manager (MonoDevelop | Add-in Manager... on Mac OSX and Tools | Add-in Manager on Windows).

3. Switch to the Gallery tab and install "F# Language Binding".

That's it. You're now ready to start building F# applications with MonoDevelop.

An ASP.NET MVC Project with F# and MonoDevelop:

MonoDevelop also supports ASP.NET MVC. To see an example, clone https://github.com/dmohl/FsMvc4MonoSample and open the solution.

The solution includes 2 projects:

1. A web project that includes Views and Controllers.
2. A unit testing project.

A screenshot of the Solution window is shown below:


Saturday, November 10, 2012

Recording for Building Better Web Apps with F#

Last week, I provided the slides and examples used for my talk entitled Building Better Web Apps with F#. If you missed the presentation, you can watch it here:

2012-10 Building Better Web Apps with FSharp from Ryan Riley on Vimeo.

Presentation - CoffeeScript: Good, Bold, and with Sugar

Thanks to all who came out to the Nashville .NET User Group last Thursday. If you weren't able to make it, you can view the presentation here:


 

Monday, November 5, 2012

Presentation: Building Better Web Apps with F#

Thanks to all who attended the Community for F# presentation last Tuesday (10/30/2012). Here are the slides from the talk:



The end result of the examples that were built during the presentation can be downloaded from here.

Monday, October 29, 2012

Using F# Records with ASP.NET Web API

In the Knockout.js and Backbone.js examples that I provided over the last few weeks, the model was written as a class using the traditional syntax. Here's an example:

While this approach works well, it would be great if we could use F# records instead. It turns out that with a few tweaks, this is easy to accomplish. Let's see how to do this in the Knockout.js example.  

First, we'll change the model to be an F# record. The new model looks like this:

We'll also need to change how the example data is initialized. This code now looks like this:

Lastly, a small change is needed in the ContactsViewModel. This now looks like the following:

Wednesday, October 17, 2012

Rough Cut of Building Web, Cloud, and Mobile Solutions with F#

Back in May I talked about two books that were currently underway. Today I'm proud to say that one of those books is now available as a Rough Cut on Safari Books Online.


I hope you enjoy reading it as much as I enjoyed writing it! A huge thanks goes to Ryan Riley for his continued expertise and guidance as the technical reviewer.