<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Matt&#039;s work blog</title>
	<atom:link href="http://mattfrear.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://mattfrear.com</link>
	<description>.NET development from London.</description>
	<lastBuildDate>Tue, 21 Feb 2012 14:56:28 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='mattfrear.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://1.gravatar.com/blavatar/947c1ebe9baa6b4763ba4971108706ea?s=96&#038;d=http%3A%2F%2Fs2.wp.com%2Fi%2Fbuttonw-com.png</url>
		<title>Matt&#039;s work blog</title>
		<link>http://mattfrear.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://mattfrear.com/osd.xml" title="Matt&#039;s work blog" />
	<atom:link rel='hub' href='http://mattfrear.com/?pushpress=hub'/>
		<item>
		<title>Create a Movie Database Application with FubuMVC</title>
		<link>http://mattfrear.com/2012/01/25/fubumvc-movies/</link>
		<comments>http://mattfrear.com/2012/01/25/fubumvc-movies/#comments</comments>
		<pubDate>Wed, 25 Jan 2012 12:12:49 +0000</pubDate>
		<dc:creator>mattfrear</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[fubumvc]]></category>

		<guid isPermaLink="false">http://mattfrear.com/?p=512</guid>
		<description><![CDATA[I decided to have a look at FubuMVC, mainly to see what it offers over ASP.NET MVC. To do so I tasked myself with creating a simple Movies app, ala Stephen Walter&#8217;s Movie Database ASP.NET MVC tutorial. So the requirements of the application are: List a set of movie database records Create a new movie <a href="http://mattfrear.com/2012/01/25/fubumvc-movies/" class="excerpt-more-link">[&#8230;]</a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mattfrear.com&amp;blog=12300335&amp;post=512&amp;subd=mattfrear&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I decided to have a look at <a href="http://fubumvc.com/">FubuMVC</a>, mainly to see what it offers over ASP.NET MVC. To do so I tasked myself with creating a simple Movies app, ala Stephen Walter&#8217;s <a href="http://www.asp.net/mvc/tutorials/movie-database/create-a-movie-database-application-in-15-minutes-with-asp-net-mvc-cs">Movie Database ASP.NET MVC tutorial</a>.</p>
<p>So the requirements of the application are:</p>
<ol>
<li>List a set of movie database records</li>
<li>Create a new movie database record (with validation!)</li>
<li>Edit an existing movie database record</li>
</ol>
<h3>Let&#8217;s go</h3>
<p>In Visual Studio, File -&gt; New Project -&gt; Web -&gt; ASP.NET Empty Web Application. Name it MovieApp.</p>
<p>Next, add FubuMVC via nuget (right-click MovieApp project, Manage NuGet packages, and search for FubuMVC).</p>
<p>Press F5 to check you get the FubuMVC welcome page.</p>
<p><a href="http://mattfrear.files.wordpress.com/2012/01/welcome.png"><img class="aligncenter size-full wp-image-513" title="welcome" src="http://mattfrear.files.wordpress.com/2012/01/welcome.png?w=500&#038;h=347" alt="" width="500" height="347" /></a></p>
<h3>Create the database</h3>
<p>As per Stephen&#8217;s <a href="http://www.asp.net/mvc/tutorials/movie-database/create-a-movie-database-application-in-15-minutes-with-asp-net-mvc-cs">tutorial</a>, I&#8217;m going to use SQL Server and Entity Framework for the data layer.</p>
<p>See his tutorial for instructions on how to set that up using Visual Studio. If you have SQL Server Management Studio then create a new database called MoviesDB, and run the following script to create a table.</p>
<p><pre class="brush: sql;">
CREATE TABLE [dbo].[Movies](
 [Id] [int] IDENTITY(1,1) NOT NULL,
 [Title] [nvarchar](255) NOT NULL,
 [Director] [nvarchar](255) NOT NULL,
 [DateReleased] [datetime] NOT NULL,
 [Synopsis] [ntext] NOT NULL,
 [ImageUri] [nvarchar](255) NOT NULL,
 CONSTRAINT [PK_Movies] PRIMARY KEY CLUSTERED
(
 [Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
SET IDENTITY_INSERT [dbo].[Movies] ON
INSERT [dbo].[Movies] ([Id], [Title], [Director], [DateReleased], [Synopsis], [ImageUri]) VALUES (1, N'Star Wars', N'George Lucas', CAST(0x00006DDC00000000 AS DateTime), N'Part IV in George Lucas'' epic, Star Wars: A New Hope opens with a Rebel ship being boarded by the tyrannical Darth Vader. The plot then follows the life of a simple farm boy, Luke Skywalker, as he and his newly met allies (Han Solo, Chewbacca, Obi-Wan Kenobi, C-3PO, R2-D2) attempt to rescue a Rebel leader, Princess Leia, from the clutches of the Empire. The conclusion is culminated as the Rebels, including Skywalker and flying ace Wedge Antilles make an attack on the Empire''s most powerful and ominous weapon, the Death Star.', N'http://ia.media-imdb.com/images/M/MV5BMTU4NTczODkwM15BMl5BanBnXkFtZTcwMzEyMTIyMw@@._V1._SY317_.jpg')
INSERT [dbo].[Movies] ([Id], [Title], [Director], [DateReleased], [Synopsis], [ImageUri]) VALUES (2, N'Pulp Fiction', N'Quentin Tarantino', CAST(0x0000861D00000000 AS DateTime), N'Jules Winnfield and Vincent Vega are two hitmen who are out to retrieve a suitcase stolen from their employer, mob boss Marsellus Wallace. Wallace has also asked Vincent to take his wife Mia out a few days later when Wallace himself will be out of town. Butch Coolidge is an aging boxer who is paid by Wallace to lose his next fight. The lives of these seemingly unrelated people are woven together comprising of a series of funny, bizarre and uncalled-for incidents', N'http://ia.media-imdb.com/images/M/MV5BMjE0ODk2NjczOV5BMl5BanBnXkFtZTYwNDQ0NDg4._V1._SY317_CR4,0,214,317_.jpg')
INSERT [dbo].[Movies] ([Id], [Title], [Director], [DateReleased], [Synopsis], [ImageUri]) VALUES (3, N'Memento', N'Christopher Nolan', CAST(0x00008FD100000000 AS DateTime), N'Memento chronicles two separate stories of Leonard, an ex-insurance investigator who can no longer build new memories, as he attempts to find the murderer of his wife, which is the last thing he remembers. One story line moves forward in time while the other tells the story backwards revealing more each time.', N'http://ia.media-imdb.com/images/M/MV5BMjA3MTkzMzI3N15BMl5BanBnXkFtZTcwNzYwMzQ4MQ@@._V1._SY317_.jpg')
SET IDENTITY_INSERT [dbo].[Movies] OFF
</pre></p>
<p>I&#8217;ve added a couple of extra columns &#8211; ImageUri and Synopsis.</p>
<h3>Create the Model</h3>
<p>Back in Visual Studio, right-click on MovieApp and choose Add -&gt; New Folder, and name it &#8216;Model&#8217;.</p>
<p>Right-click the Model folder, and choose Add -&gt; New Item&#8230;, then Data -&gt; ADO.NET Entity Data Model. Name it Movies.edmx. Select Generate from database, click Next. Choose the MoviesDB you just created, and click Next. Tick the Tables checkbox, and click Finish. Now click on the entity &#8216;Movy&#8217;. Open the Properties pane, and change its name to &#8216;Movie&#8217; and the Entity Set Name to &#8216;Movies&#8217;.</p>
<p>With me so far? We should have something like this:</p>
<p><a href="http://mattfrear.files.wordpress.com/2012/01/edmx.png"><img class="aligncenter size-full wp-image-516" title="edmx" src="http://mattfrear.files.wordpress.com/2012/01/edmx.png?w=500&#038;h=423" alt="" width="500" height="423" /></a></p>
<h3>Create the FubuMVC Controller</h3>
<p>FubuMVC isn&#8217;t as strict about what makes a controller as ASP.NET MVC. In fact, that is one of fubu&#8217;s big features &#8211; you can define your own conventions about what make a Controller (or a Handler in fubu-parlance). But in the interests of keeping this tutorial simple, I&#8217;m going to stick to the &#8216;ClassesSuffixedWithController&#8217; convention.</p>
<p>Right-click MovieApp, Add -&gt; New Folder, named &#8216;Movies&#8217;.<br />
Right-click Movies folder, Add -&gt; Class, named <b>IndexController.cs</b>:</p>
<p><pre class="brush: csharp;">
using System.Collections.Generic;
using System.Linq;
using MovieApp.Model;

namespace MovieApp.Movies
{
    public class IndexController
    {
        private MoviesDBEntities _db = new MoviesDBEntities();

        public ViewModel Index(InputModel model)
        {
            return new ViewModel { Movies = _db.Movies.ToList() };
        }

        public class InputModel
        { 
        }

        public class ViewModel
        {
            public IEnumerable&lt;Movie&gt; Movies { get; set; }
        }
    }
}
</pre></p>
<p>Because of the namespace (MoviesApp.<strong>Movies</strong>) and the name of the Action (public ViewModel <strong>Index</strong>(InputModel model)), the Index method is going to get hit when we navigate to /Movies/Index.</p>
<p>One of the best practices of FubuMVC is the OMIOMO rule &#8211; One Model In, One Model Out. This means every controller Action should have one unique model passed to it, and should return a different model.</p>
<p>My preference is to keep these Model classes nested in the Controller class to reduce namespace clutter, but you don&#8217;t have to.</p>
<p>So you can see that the Index method takes an instance of IndexController.Index, and returns an instance of IndexController.ViewModel.</p>
<h3>Add a ViewEngine</h3>
<p>FubuMVC supports the Spark view engine, the Web Forms view engine, and as of writing the Razor view engine is a work in progress.<br />
I didn&#8217;t feel like learning Spark, and since Razor isn&#8217;t finished yet, I&#8217;ll use the Web Forms view engine (ala ASP.NET MVC1), which means .aspx files with a code-behind .aspx.cs &#8211; sorry about that.</p>
<p>Add the FubuMVC.WebForms NuGet package.</p>
<p>Now open <strong>/ConfigureFubuMVC.cs</strong>, and add the following lines:</p>
<p><pre class="brush: csharp;">
public ConfigureFubuMVC()
{
    ....
    // View Engine
    Import&lt;WebFormsEngine&gt;();
}
</pre></p>
<h3>Add the &#8216;Index&#8217; View</h3>
<p>Now right-click the Movies folder, Add -&gt; New Item. Choose Web Form, and name it Index.aspx.<br />
Delete the Index.aspx.designer.cs &#8211; we don&#8217;t need it.<br />
Open the <strong>Index.aspx.cs</strong>, delete the existing code and replace it with this:<br />
<pre class="brush: csharp;">
using FubuMVC.WebForms;
namespace MovieApp.Movies
{
    public partial class Index : FubuPage&lt;IndexController.ViewModel&gt;
    {
    }
}
</pre><br />
This tells Index.aspx that its Model is an IndexController.ViewModel.<br />
Now open <strong>Index.aspx</strong>, and replace it with this:<br />
<pre class="brush: xml;">
&lt;%@ Page Language=&quot;C#&quot; AutoEventWireup=&quot;true&quot; CodeBehind=&quot;Index.aspx.cs&quot; Inherits=&quot;MovieApp.Movies.Index&quot; %&gt;
&lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&gt;
&lt;head id=&quot;Head1&quot; runat=&quot;server&quot;&gt;
    &lt;title&gt;All Movies&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
    &lt;% foreach (var movie in Model.Movies)
       { %&gt;
            &lt;h3&gt;&lt;%: movie.Title %&gt;&lt;/h3&gt;
            &lt;b&gt;Director:&lt;/b&gt; &lt;%: movie.Director %&gt;&lt;br /&gt;
            &lt;b&gt;Date released:&lt;/b&gt; &lt;%: movie.DateReleased.ToString(&quot;MMM yyyy&quot;) %&gt;&lt;br /&gt;
            &lt;%: movie.Synopsis %&gt;&lt;br /&gt;
    &lt;% } %&gt;
&lt;/body&gt;
&lt;/html&gt;
</pre></p>
<p>Notice that in the view we can use the &#8216;Model&#8217; keyword just like in ASP.NET MVC.<br />
Now press Ctrl-F5, and navigate to /movies/index, and you should see:<br />
<a href="http://mattfrear.files.wordpress.com/2012/01/allmovies.png"><img src="http://mattfrear.files.wordpress.com/2012/01/allmovies.png?w=500&#038;h=433" alt="" title="allmovies" width="500" height="433" class="aligncenter size-full wp-image-520" /></a></p>
<p>Remember, our Action is /Movies/Index because of the Controller&#8217;s namespace (MovieApp.<strong>Movies</strong>) + the name of the Action method (public ViewModel <strong>Index</strong>(InputModel model)). The Webforms view engine will look for a corresponding View in the same path &#8211; ~/Movies/, which has the same underlying Model type as the one returned by the Index action method &#8211; &#8220;IndexController.ViewModel&#8221;. Our Index.aspx.cs sets this (public partial class Index : FubuPage&lt;<strong>IndexController.ViewModel</strong>&gt;).</p>
<h3>Add an Edit Movie page</h3>
<p>Another FubuMVC recommendation is to have a separate Controller/Handler per action.<br />
So let&#8217;s Right click the Movies folder, Add -&gt; Class, and name it <strong>EditController.cs</strong>:<br />
<pre class="brush: csharp;">
using System.Linq;
using FubuMVC.Core.Continuations;
using MovieApp.Model;

namespace MovieApp.Movies
{
    public class EditController
    {
        private MoviesDBEntities _db = new MoviesDBEntities();

        public Movie Get_Movies_Edit_MovieId(InputModel input)
        {
            return _db.Movies.FirstOrDefault(x =&gt; x.Id == input.MovieId);
        }

        public FubuContinuation Post_Movies_Edit(Movie input)
        {
            var movie = _db.Movies.First(m =&gt; m.Id == input.Id);
            movie.Title = input.Title;
            movie.Director = input.Director;
            movie.DateReleased = input.DateReleased;
            movie.Synopsis = input.Synopsis;

            _db.SaveChanges();
            return FubuContinuation.RedirectTo(new IndexController.InputModel());
        }

        public class InputModel
        {
            public int MovieId { get; set; }
        }
    }
}
</pre></p>
<p>This time, the name of the Action (Get_Movies_Edit_MovieId) follows another one of Fubu&#8217;s built-in conventions &#8211; underscores are replaced by /. So this Action will get hit when you navigate to /Movies/Edit/1. The Get at the front means we are restricting to HTTP GETs only.</p>
<p>Now let&#8217;s add the view.<br />
Add a new Web Form as before, call it Edit.aspx. <strong>Edit.aspx.cs</strong>:<br />
<pre class="brush: csharp;">
using FubuMVC.WebForms;
using MovieApp.Model;

namespace MovieApp.Movies
{
    public partial class Edit : FubuPage&lt;Movie&gt;
    {
    }
}
</pre></p>
<p><strong>Edit.aspx</strong>:<br />
<pre class="brush: xml;">
&lt;%@ Page Language=&quot;C#&quot; AutoEventWireup=&quot;true&quot; CodeBehind=&quot;Edit.aspx.cs&quot; Inherits=&quot;MovieApp.Movies.Edit&quot; %&gt;
&lt;%@ Import Namespace=&quot;MovieApp.Movies&quot; %&gt;

&lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&gt;
&lt;head runat=&quot;server&quot;&gt;
    &lt;title&gt;Edit Movie&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;% if (Model != null)
   { %&gt;
    &lt;%= this.FormFor(Model) %&gt;
        &lt;input type=&quot;hidden&quot; name=&quot;Id&quot; value=&quot;&lt;%= Model.Id %&gt;&quot; /&gt;
        &lt;fieldset&gt;
            &lt;legend&gt;Edit Movie&lt;/legend&gt;
            &lt;p&gt;
                &lt;%= this.LabelFor(m =&gt; m.Title) %&gt;&lt;%= this.InputFor(m =&gt; m.Title) %&gt;
            &lt;/p&gt;
            &lt;p&gt;
                &lt;%= this.LabelFor(m =&gt; m.Director) %&gt;&lt;%= this.InputFor(m =&gt; m.Director) %&gt;
            &lt;/p&gt;
            &lt;p&gt;
                &lt;%= this.LabelFor(m =&gt; m.DateReleased) %&gt;&lt;input type=&quot;text&quot; name=&quot;DateReleased&quot; value=&quot;&lt;%: Model.DateReleased.ToShortDateString() %&gt;&quot; /&gt;
            &lt;/p&gt;
            &lt;p&gt;
                &lt;%= this.LabelFor(m =&gt; m.ImageUri) %&gt;&lt;%= this.InputFor(m =&gt; m.ImageUri) %&gt;
            &lt;/p&gt;
            &lt;p&gt;
                &lt;%= this.LabelFor(m =&gt; m.Synopsis) %&gt;&lt;textarea name=&quot;Synopsis&quot; rows=&quot;15&quot; cols=&quot;70&quot;&gt;&lt;%: Model.Synopsis %&gt;&lt;/textarea&gt;
            &lt;/p&gt;
        &lt;/fieldset&gt;
        &lt;input type=&quot;submit&quot; value=&quot;Save&quot; /&gt; 
        &lt;%= this.LinkTo(new IndexController.InputModel()).Text(&quot;Cancel&quot;) %&gt;
    &lt;%= this.EndForm() %&gt;
&lt;% } %&gt;
&lt;/body&gt;
&lt;/html&gt;
</pre></p>
<p>Notice that this time we&#8217;re using some of FubuMVC&#8217;s built-in HtmlTag helpers &#8211; this.FormFor(), this.LabelFor(), this.InputFor() etc.<br />
One thing I like is the<br />
<pre class="brush: xml;">
&lt;%= this.FormFor(Model) %&gt;
</pre><br />
This renders to:<br />
<pre class="brush: xml;">
   &lt;form id=&quot;mainForm&quot; method=&quot;post&quot; action=&quot;/movies/edit&quot;&gt;
</pre><br />
Fubu is smart enough to put action=&#8221;/movies/edit&#8221; on the form &#8211; because FormFor(Model) is saying give me a form for the Model, and it knows the Model of type Movie, so it looks for any Action that takes a <strong>Movie</strong> as input. The Action it wants is defined in the EditController (public FubuContinuation Post_Movies_Edit(<strong>Movie</strong> input)) but it&#8217;s important to note that this Action could be anywhere and could be named anything. For example, if I rename the Post_Movies_Edit() method to &#8220;DumDeeDoo()&#8221;, then FormFor renders the form with<br />
<pre class="brush: xml;">
&lt;form id=&quot;mainForm&quot; method=&quot;post&quot; action=&quot;/movies/dumdeedoo&quot;&gt;
</pre><br />
Note that the name of the Post method is following the same convention as the Get &#8211; Post_Movies_Edit exists at /Movies/Edit and will accept HTTP POSTs only. It returns a FubuContinuation which redirects us back to the Home page (/Movies/Index).</p>
<p>Now let&#8217;s look at the Cancel link at the bottom.<br />
<pre class="brush: xml;">
&lt;%= this.LinkTo(new IndexController.InputModel()).Text(&quot;Cancel&quot;) %&gt;
</pre><br />
Renders to:<br />
<pre class="brush: xml;">
&lt;a href=&quot;/movies/index&quot;&gt;Cancel&lt;/a&gt;
</pre><br />
As with the FormFor, with &#8220;LinkTo&#8221; I ask for a link to an InputModel. This differs from the ASP.NET MVC approach of asking for an Html.ActionLink to a specific Action method. Fubu&#8217;s way is pretty cool &#8211; cos if I rename my actions or restructure the site, the links will still render the correct URLs.</p>
<h3>Add Validation</h3>
<p>Unfortunately validation isn&#8217;t included in the box, but we can add it. But it&#8217;s a pain in the ass.<br />
First add the<strong> FubuMVC.Validation NuGet package</strong>.<br />
Next change your <strong>/App_Start/FubuMVC.cs</strong><br />
<pre class="brush: csharp; wrap-lines: false;">
using Bottles;
using FubuMVC.Core;
using FubuMVC.StructureMap;
using FubuValidation.StructureMap;
using StructureMap.Configuration.DSL;

// You can remove the reference to WebActivator by calling the Start() method from your Global.asax Application_Start
[assembly: WebActivator.PreApplicationStartMethod(typeof(MovieApp.App_Start.AppStartFubuMVC), &quot;Start&quot;, callAfterGlobalAppStart: true)]

namespace MovieApp.App_Start
{
    public static class AppStartFubuMVC
    {
        public static void Start()
        {
            // FubuApplication &quot;guides&quot; the bootstrapping of the FubuMVC
            // application
            FubuApplication.For&lt;ConfigureFubuMVC&gt;() // ConfigureFubuMVC is the main FubuRegistry
                                                    // for this application.  FubuRegistry classes 
                                                    // are used to register conventions, policies,
                                                    // and various other parts of a FubuMVC application


                // FubuMVC requires an IoC container for its own internals.
                .StructureMapObjectFactory(configure =&gt; configure.AddRegistry&lt;MovieAppRegistry&gt;())
                .Bootstrap();

			// Ensure that no errors occurred during bootstrapping
			PackageRegistry.AssertNoFailures();
        }

        public class MovieAppRegistry : Registry
        {
            public MovieAppRegistry()
            {
                Scan(x =&gt;
                {
                    x.TheCallingAssembly();
                    x.WithDefaultConventions();
                });

                this.FubuValidation();
            }
        }
    }
}
</pre></p>
<p>Now add these lines to <strong>/ConfigureFubuMVC.cs</strong><br />
<pre class="brush: csharp; wrap-lines: false;">
public ConfigureFubuMVC()
{
    ...
    Views.TryToAttachWithDefaultConventions()
                .RegisterActionLessViews(t =&gt; t.ViewModelType == typeof(FubuValidation.Notification));

    this.Validation(validation =&gt; {
        // Include all action calls that: 1) have input and 2) whose input models contain the string &quot;Post&quot;
        // We use a convention in this sample that models for POST ActionCalls contain &quot;Post&quot;
        validation
            .Actions
            .Include(call =&gt; call.HasInput &amp;&amp; call.InputType().Name.Contains(&quot;Post&quot;));

        // This DSL reads as follows...
        // When handling failures:
        //  If the input type of the action call is not null and the name of the model contains the string &quot;Post&quot;,
        //  Then Transfer to a behavior chain that is resolved by my custom HandlerModelDescriptor class
        validation
            .Failures
            .If(f =&gt; f.InputType() != null &amp;&amp; f.InputType().Name.Contains(&quot;Post&quot;))
            .TransferBy&lt;HandlerModelDescriptor&gt;();
    });
}
</pre><br />
The above is saying that we&#8217;re adding validation to any method that takes an input, and has &#8220;Post&#8221; in its name.<br />
The method it will redirect to if validation fails is determined by the HandlerModelDescriptor class, which we will now add.</p>
<p><strong>/HandlerModelDescriptor.cs</strong><br />
<pre class="brush: csharp; wrap-lines: false;">
using System;
using System.Linq;
using FubuMVC.Core.Registration;
using FubuMVC.Validation;

namespace MovieApp
{
    public class HandlerModelDescriptor : IFubuContinuationModelDescriptor
    {
        private readonly BehaviorGraph _graph;

        public HandlerModelDescriptor(BehaviorGraph graph)
        {
            _graph = graph;
        }

        public Type DescribeModelFor(ValidationFailure context)
        {
            // Remember, behavior chains can be identified by the input model type
            // The IFubuContinuationModelDescriptor interface is used to describe the input model type of the chain
            // that we want to transfer to

            // we're going to query the BehaviorGraph to find the corresponding GET for the POST
            // obviously, we'd need to make this smarter but this is just a simple example
            var targetName = context.Target.HandlerType.Name;
            var getCall = _graph
                .Behaviors
                .Where(chain =&gt; chain.FirstCall() != null &amp;&amp; chain.FirstCall().HandlerType.Name == targetName
                    &amp;&amp; chain.Route.AllowedHttpMethods.Contains(&quot;GET&quot;))
                .Select(chain =&gt; chain.FirstCall())
                .FirstOrDefault();
            
            if(getCall == null)
            {
                return null;
            }

            return getCall.InputType();
        }
    }
}
</pre></p>
<p>This is called when validation fails. It returns the Input Type of the method to pass control to.<br />
To find it, it looks for an HTTP GET method inside the same Controller as the method doing the POSTing.</p>
<p>Now we need to add a View which is called when validation is needed.<br />
Add a new folder, /Shared.<br />
<strong>/Shared/ValidationSummary.aspx</strong><br />
<pre class="brush: xml;">
&lt;%@ Page Language=&quot;C#&quot; AutoEventWireup=&quot;true&quot; CodeBehind=&quot;ValidationSummary.aspx.cs&quot; Inherits=&quot;MovieApp.Shared.ValidationSummary&quot; %&gt;

&lt;% if (Model.AllMessages.Any()) { %&gt;
    &lt;ul style=&quot;color:Red&quot;&gt;
        &lt;% foreach (var msg in Model.AllMessages)
           { %&gt;
                &lt;li&gt;&lt;%= msg %&gt;&lt;/li&gt;
        &lt;% } %&gt;
    &lt;/ul&gt;    
&lt;% } %&gt;
</pre><br />
<strong>/Shared/ValidationSummary.aspx.cs</strong><br />
<pre class="brush: csharp;">
using FubuMVC.WebForms;
namespace MovieApp.Shared
{
    public partial class ValidationSummary : FubuPage &lt;FubuValidation.Notification&gt;
    {
    }
}
</pre></p>
<h3>Add a Create Movie page (with validation)</h3>
<p><strong>/Movies/CreateController.cs</strong><br />
<pre class="brush: csharp;">
using System;
using FubuMVC.Core.Continuations;
using FubuValidation;
using MovieApp.Model;

namespace MovieApp.Movies
{
    public class CreateController
    {
        private MoviesDBEntities _db = new MoviesDBEntities();

        public ViewModel Get_Movies_Create(InputModel input)
        {
            return new ViewModel { DateReleased = DateTime.Parse(&quot;01/01/2001&quot;) };
        }

        public FubuContinuation Post_Movies_Create(ViewModel input)
        {
            var movie = new Movie
            {
                Title = input.Title,
                Director = input.Director,
                DateReleased = input.DateReleased,
                ImageUri = input.ImageUri,
                Synopsis = input.Synopsis
            };

            _db.Movies.AddObject(movie);
            _db.SaveChanges();

            return FubuContinuation.RedirectTo(new IndexController.InputModel());
        }

        public class InputModel
        {
        }

        public class ViewModel
        {
            [Required]
            public string Title { get; set; }
            [Required]
            [MaximumStringLength(50)]
            public string Director { get; set; }
            [Required]
            public DateTime DateReleased { get; set; }
            [Required]
            public string ImageUri { get; set; }
            [Required]
            public string Synopsis { get; set; }
        }
    }
}
</pre></p>
<p>I&#8217;ve taken a best practice approach with the Create &#8211; by binding to a view model (ViewModel), instead of binding directly to the Movie domain object. This also allows me to add FubuValidation attributes like [Required].</p>
<p><strong>/Movies/Create.aspx</strong><br />
<pre class="brush: xml; wrap-lines: false;">
&lt;%@ Page Language=&quot;C#&quot; AutoEventWireup=&quot;true&quot; CodeBehind=&quot;Create.aspx.cs&quot; Inherits=&quot;MovieApp.Movies.Create&quot; %&gt;
&lt;%@ Import Namespace=&quot;MovieApp.Movies&quot; %&gt;

&lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&gt;
&lt;head runat=&quot;server&quot;&gt;
    &lt;title&gt;Create Movie&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
    &lt;%= this.FormFor(Model) %&gt;
        &lt;fieldset&gt;
            &lt;legend&gt;Create Movie&lt;/legend&gt;
            &lt;%= this.Partial&lt;FubuValidation.Notification&gt;() %&gt;
            &lt;p&gt;
                &lt;%= this.LabelFor(m =&gt; m.Title) %&gt;&lt;%= this.InputFor(m =&gt; m.Title) %&gt;
            &lt;/p&gt;
            &lt;p&gt;
                &lt;%= this.LabelFor(m =&gt; m.Director) %&gt;&lt;%= this.InputFor(m =&gt; m.Director) %&gt;
            &lt;/p&gt;
            &lt;p&gt;
                &lt;%= this.LabelFor(m =&gt; m.DateReleased) %&gt;&lt;input type=&quot;text&quot; name=&quot;DateReleased&quot; value=&quot;&lt;%: Model.DateReleased.ToShortDateString() %&gt;&quot; /&gt;
            &lt;/p&gt;
            &lt;p&gt;
                &lt;%= this.LabelFor(m =&gt; m.ImageUri) %&gt;&lt;%= this.InputFor(m =&gt; m.ImageUri) %&gt;
            &lt;/p&gt;
            &lt;p&gt;
                &lt;%= this.LabelFor(m =&gt; m.Synopsis) %&gt;&lt;textarea name=&quot;Synopsis&quot; rows=&quot;15&quot; cols=&quot;70&quot;&gt;&lt;%: Model.Synopsis %&gt;&lt;/textarea&gt;
            &lt;/p&gt;
        &lt;/fieldset&gt;
        &lt;input type=&quot;submit&quot; value=&quot;Save&quot; /&gt; &lt;%= this.LinkTo(new IndexController.InputModel()).Text(&quot;Cancel&quot;) %&gt;
    &lt;%= this.EndForm() %&gt;
&lt;/body&gt;
&lt;/html&gt;
</pre><br />
<strong>/Movies/Create.aspx.cs</strong><br />
<pre class="brush: csharp;">
using FubuMVC.WebForms;
namespace MovieApp.Movies
{
    public partial class Create : FubuPage&lt;CreateController.ViewModel&gt;
    {
    }
}
</pre></p>
<p>If all works correctly, you should be able to navigate to /Movies/Create, and see the following:<br />
<a href="http://mattfrear.files.wordpress.com/2012/01/create.png"><img src="http://mattfrear.files.wordpress.com/2012/01/create.png?w=500&#038;h=417" alt="" title="create" width="500" height="417" class="aligncenter size-full wp-image-534" /></a><br />
and then if we don&#8217;t enter a Required field, we get the Validation summary at the top:<br />
<a href="http://mattfrear.files.wordpress.com/2012/01/validation.png"><img src="http://mattfrear.files.wordpress.com/2012/01/validation.png?w=500&#038;h=417" alt="" title="validation" width="500" height="417" class="aligncenter size-full wp-image-535" /></a><br />
Unfortunately that&#8217;s all you get for validation &#8211; no message alongside the invalid field. And the values which the user previously entered aren&#8217;t persisted, which is annoying.</p>
<h3>Finishing touches</h3>
<p>I&#8217;ll add a quick skin using one of the great templates at <a href="http://www.freecsstemplates.org/">freecsstemplates.org</a>. I&#8217;ll also add a link to the Create, and Edit pages, and also a Delete Movie button.<br />
<a href="http://mattfrear.files.wordpress.com/2012/01/fubumovies.png"><img src="http://mattfrear.files.wordpress.com/2012/01/fubumovies.png?w=500&#038;h=326" alt="" title="fubumovies" width="500" height="326" class="aligncenter size-full wp-image-536" /></a></p>
<p>You can see the sample application <a href="http://fubumovies.apphb.com/">running here on AppHarbor</a>. Click on the Title of a Movie to edit it &#8211; NB. the first 3 sample movies are read-only.</p>
<p>You can download the source code from <a href="http://bitbucket.org/mattfrear/fubumovies">bitbucket</a>.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/mattfrear.wordpress.com/512/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/mattfrear.wordpress.com/512/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/mattfrear.wordpress.com/512/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/mattfrear.wordpress.com/512/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/mattfrear.wordpress.com/512/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/mattfrear.wordpress.com/512/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/mattfrear.wordpress.com/512/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/mattfrear.wordpress.com/512/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/mattfrear.wordpress.com/512/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/mattfrear.wordpress.com/512/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/mattfrear.wordpress.com/512/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/mattfrear.wordpress.com/512/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/mattfrear.wordpress.com/512/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/mattfrear.wordpress.com/512/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mattfrear.com&amp;blog=12300335&amp;post=512&amp;subd=mattfrear&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://mattfrear.com/2012/01/25/fubumvc-movies/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/5da3065d9a83a23a90c18a5e7d20b180?s=96&#38;d=http%3A%2F%2F1.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">mattfrear</media:title>
		</media:content>

		<media:content url="http://mattfrear.files.wordpress.com/2012/01/welcome.png" medium="image">
			<media:title type="html">welcome</media:title>
		</media:content>

		<media:content url="http://mattfrear.files.wordpress.com/2012/01/edmx.png" medium="image">
			<media:title type="html">edmx</media:title>
		</media:content>

		<media:content url="http://mattfrear.files.wordpress.com/2012/01/allmovies.png" medium="image">
			<media:title type="html">allmovies</media:title>
		</media:content>

		<media:content url="http://mattfrear.files.wordpress.com/2012/01/create.png" medium="image">
			<media:title type="html">create</media:title>
		</media:content>

		<media:content url="http://mattfrear.files.wordpress.com/2012/01/validation.png" medium="image">
			<media:title type="html">validation</media:title>
		</media:content>

		<media:content url="http://mattfrear.files.wordpress.com/2012/01/fubumovies.png" medium="image">
			<media:title type="html">fubumovies</media:title>
		</media:content>
	</item>
		<item>
		<title>jsTree tri-state checkboxes with ASP.NET MVC revisited</title>
		<link>http://mattfrear.com/2011/12/17/jstree-revisited/</link>
		<comments>http://mattfrear.com/2011/12/17/jstree-revisited/#comments</comments>
		<pubDate>Sat, 17 Dec 2011 23:30:54 +0000</pubDate>
		<dc:creator>mattfrear</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://mattfrear.wordpress.com/?p=481</guid>
		<description><![CDATA[My original jsTree checkboxes post is still my most popluar, yet it is 18 months old and no longer works with the latest version of jsTree (pre 1.0). Since that post is so popular I thought I should update it. My first surprise was how much the jsTree guys changed their API between releases &#8211; <a href="http://mattfrear.com/2011/12/17/jstree-revisited/" class="excerpt-more-link">[&#8230;]</a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mattfrear.com&amp;blog=12300335&amp;post=481&amp;subd=mattfrear&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>My <a title="Using jsTree to get a Treeview with checkboxes in ASP.NET MVC" href="http://mattfrear.com/2010/05/19/jstree/">original jsTree checkboxes post</a> is still my most popluar, yet it is 18 months old and no longer works with the latest version of jsTree (pre 1.0). Since that post is so popular I thought I should update it.</p>
<p>My first surprise was how much the <a href="http://www.jstree.com/">jsTree</a> guys changed their API between releases &#8211; I was only going from version 0.9.9 to version 1.0, but  I had to practically start from scratch.</p>
<p>So, without further ado:</p>
<p><a href="http://www.jstree.com/" target="_blank">jsTree</a> is a jQuery plugin for creating a treeviews, and jsTree’s checkbox plugin allows you to create a treeview with tri-state checkboxes, like so:</p>
<p><a href="http://mattfrear.files.wordpress.com/2010/05/jstree.jpg"><img class="aligncenter size-full wp-image-118" title="jstree" src="http://mattfrear.files.wordpress.com/2010/05/jstree.jpg?w=500" alt=""   /></a></p>
<p>Notice how “Origination” appears half-checked because only some of its children are checked.</p>
<h4>Getting started</h4>
<p>For this demo I am using ASP.NET MVC 3 and<strong> jsTree pre 1.0 fixed</strong>. Let’s start with a new “ASP.NET MVC 3 Web Application”, choose Internet Application, name it jsTreeDemo, and add the required jsTree files to our solution:</p>
<p><a href="http://mattfrear.files.wordpress.com/2011/12/jstree-files.png"><img class="aligncenter size-full wp-image-482" title="jstree files" src="http://mattfrear.files.wordpress.com/2011/12/jstree-files.png?w=500" alt=""   /></a></p>
<p>In the View, create a div which you want to become a treeview. I’ll name mine demoTree. Also add references to the jsTree script, and add a new index.js file for our custom javascript.</p>
<p>Views/Home/Index.cshtml</p>
<p><pre class="brush: xml;">
@{
 ViewBag.Title = &quot;Home Page&quot;;
}

&lt;h2&gt;@ViewBag.Message&lt;/h2&gt;

&lt;div id=&quot;demoTree&quot;&gt;

&lt;/div&gt;
&lt;script type=&quot;text/javascript&quot;&gt;
treeModel = [{&quot;data&quot;:&quot;Confirm Application&quot;,&quot;attr&quot;:{&quot;id&quot;:&quot;10&quot;},&quot;children&quot;:null},{&quot;data&quot;:&quot;Things&quot;,&quot;attr&quot;:{&quot;id&quot;:&quot;20&quot;},&quot;children&quot;:[{&quot;data&quot;:&quot;Thing 1&quot;,&quot;attr&quot;:{&quot;id&quot;:&quot;21&quot;},&quot;children&quot;:null},{&quot;data&quot;:&quot;Thing 2&quot;,&quot;attr&quot;:{&quot;id&quot;:&quot;22&quot;},&quot;children&quot;:null},{&quot;data&quot;:&quot;Thing 3&quot;,&quot;attr&quot;:{&quot;id&quot;:&quot;23&quot;},&quot;children&quot;:null},{&quot;data&quot;:&quot;Thing 4&quot;,&quot;attr&quot;:{&quot;id&quot;:&quot;24&quot;},&quot;children&quot;:[{&quot;data&quot;:&quot;Thing 4.1&quot;,&quot;attr&quot;:{&quot;id&quot;:&quot;241&quot;},&quot;children&quot;:null},{&quot;data&quot;:&quot;Thing 4.2&quot;,&quot;attr&quot;:{&quot;id&quot;:&quot;242&quot;},&quot;children&quot;:null},{&quot;data&quot;:&quot;Thing 4.3&quot;,&quot;attr&quot;:{&quot;id&quot;:&quot;243&quot;},&quot;children&quot;:null}]}]},{&quot;data&quot;:&quot;Colors&quot;,&quot;attr&quot;:{&quot;id&quot;:&quot;40&quot;},&quot;children&quot;:[{&quot;data&quot;:&quot;Red&quot;,&quot;attr&quot;:{&quot;id&quot;:&quot;41&quot;},&quot;children&quot;:null},{&quot;data&quot;:&quot;Green&quot;,&quot;attr&quot;:{&quot;id&quot;:&quot;42&quot;},&quot;children&quot;:null},{&quot;data&quot;:&quot;Blue&quot;,&quot;attr&quot;:{&quot;id&quot;:&quot;43&quot;},&quot;children&quot;:null},{&quot;data&quot;:&quot;Yellow&quot;,&quot;attr&quot;:{&quot;id&quot;:&quot;44&quot;},&quot;children&quot;:null}]}];
&lt;/script&gt;
&lt;script src=&quot;@Url.Content(&quot;~/Scripts/jquery.jstree.js&quot;)&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt;
&lt;script src=&quot;@Url.Content(&quot;~/Scripts/index.js&quot;)&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt;
</pre></p>
<p>Scripts/index.js</p>
<p><pre class="brush: jscript;">
/// &lt;reference path=&quot;jquery-1.7.1-vsdoc.js&quot; /&gt;

$(function () {
   $(&quot;#demoTree&quot;).jstree({
      json_data : {
         data : treeModel
      },
      plugins : [&quot;themes&quot;, &quot;json_data&quot;, &quot;ui&quot;, &quot;checkbox&quot;]
 });
});
</pre></p>
<p>Briefly, jstree has a number of ways of poplulating the tree with data &#8211; in my previous jsTree post I was populating the tree via AJAX but for now the tree is populated via hardcoded JSON (using the built-in &quot;json_data&quot; plugin). Don&#8217;t forget to specify the &quot;checkbox&quot; plugin too.</p>
<h4>Populate the tree from a viewmodel</h4>
<p>Just like last time, let&#8217;s create a viewmodel for creating the tree structure.</p>
<p>Models/JsTreeModel.cs</p>
<p><pre class="brush: csharp;">
namespace jsTreeDemo.Models
{
  public class JsTreeModel
  {
    public string data;
    public JsTreeAttribute attr;
    public JsTreeModel[] children;
  }
  
  public class JsTreeAttribute
  {
    public string id;
    public bool selected;
  }
}
</pre></p>
<p>Now let&#8217;s change our controller to create a viewmodel, serialize it to JSON, and pass that string to our View.<br />
Controllers/HomeController.cs<br />
<pre class="brush: csharp; wrap-lines: false;">
public ActionResult Index()
{
    ViewBag.Message = &quot;Welcome!&quot;;
            
    var model = GetTreeData();
            
    string jsonModel = new JavaScriptSerializer().Serialize(model);
            
    return View(&quot;Index&quot;, &quot;_Layout&quot;, jsonModel);
}

private JsTreeModel[] GetTreeData()
{
var tree = new JsTreeModel[] 
{
    new JsTreeModel { data = &quot;Confirm Application&quot;, attr = new JsTreeAttribute { id = &quot;10&quot;, selected = true } },
    new JsTreeModel 
    { 
        data = &quot;Things&quot;,
        attr = new JsTreeAttribute { id = &quot;20&quot; },
        children = new JsTreeModel[]
            {
                new JsTreeModel { data = &quot;Thing 1&quot;, attr = new JsTreeAttribute { id = &quot;21&quot;, selected = true } },
                new JsTreeModel { data = &quot;Thing 2&quot;, attr = new JsTreeAttribute { id = &quot;22&quot; } },
                new JsTreeModel { data = &quot;Thing 3&quot;, attr = new JsTreeAttribute { id = &quot;23&quot; } },
                new JsTreeModel 
                { 
                    data = &quot;Thing 4&quot;, 
                    attr = new JsTreeAttribute { id = &quot;24&quot; },
                    children = new JsTreeModel[] 
                    { 
                        new JsTreeModel { data = &quot;Thing 4.1&quot;, attr = new JsTreeAttribute { id = &quot;241&quot; } }, 
                        new JsTreeModel { data = &quot;Thing 4.2&quot;, attr = new JsTreeAttribute { id = &quot;242&quot; } }, 
                        new JsTreeModel { data = &quot;Thing 4.3&quot;, attr = new JsTreeAttribute { id = &quot;243&quot; } }
                    },
                },
            }
    },
    new JsTreeModel 
    {
        data = &quot;Colors&quot;,
        attr = new JsTreeAttribute { id = &quot;40&quot; },
        children = new JsTreeModel[]
            {
                new JsTreeModel { data = &quot;Red&quot;, attr = new JsTreeAttribute { id = &quot;41&quot; } },
                new JsTreeModel { data = &quot;Green&quot;, attr = new JsTreeAttribute { id = &quot;42&quot; } },
                new JsTreeModel { data = &quot;Blue&quot;, attr = new JsTreeAttribute { id = &quot;43&quot; } },
                new JsTreeModel { data = &quot;Yellow&quot;, attr = new JsTreeAttribute { id = &quot;44&quot; } },
            }
    }
};

</pre></p>
<p>Views/Index.cshtml<br />
<pre class="brush: xml; highlight: [1,10];">
@model string
       
@{
    ViewBag.Title = &quot;Home Page&quot;;
}

...

&lt;script type=&quot;text/javascript&quot;&gt;
    treeModel = @Html.Raw(Model);
&lt;/script&gt;
</pre></p>
<h4>Determining which items are checked when posting</h4>
<p>Let’s put our tree inside a &lt;form&gt; and submit it.<br />
Views/Index.cshtml<br />
<pre class="brush: xml;">
...
@using (Html.BeginForm(&quot;Results&quot;, &quot;Home&quot;, FormMethod.Post))
{ 
    &lt;div id=&quot;demoTree&quot;&gt;
    &lt;/div&gt;
    &lt;br /&gt;
    &lt;div&gt;
        &lt;input type=&quot;submit&quot; value=&quot;Submit&quot; id=&quot;btnSubmit&quot; /&gt;
    &lt;/div&gt;
} 
...
</pre></p>
<p>And now let&#8217;s add the Results method to the HomeController</p>
<p>Controllers/HomeController.cs</p>
<p><pre class="brush: csharp;">
[HttpPost]
public ActionResult Results(FormCollection form)
{
    return View(form);
}
</pre></p>
<p>and the View</p>
<p>Views/Home/Results.cshtml</p>
<p><pre class="brush: xml;">
@model FormCollection

@{
    ViewBag.Title = &quot;Results&quot;;
}

&lt;h2&gt;Results&lt;/h2&gt;
&lt;p&gt;
    You chose:
    @foreach (var item in Model.AllKeys)
    {
        @Model[item]@: 
    } 
&lt;/p&gt;

&lt;p&gt;
    @Html.ActionLink(&quot;Home&quot;, &quot;Index&quot;)
&lt;/p&gt;
</pre></p>
<p>If you press the Submit button, nothing will happen as nothing is passed through in the FormCollection to Results() in HomeController. Despite appearances, jsTree doesn&#8217;t by default render any HTML &lt;input&gt;s for the checkboxes. But it&#8217;s easy enough to tell it to render them using the real_checkboxes flag:</p>
<p>Scripts/index.js<br />
<pre class="brush: jscript; highlight: [6,7,8,9,10,11];">
$(function () {
    $(&quot;#demoTree&quot;).jstree({
        json_data: {
            data: treeModel
        },
        checkbox: {
            real_checkboxes: true,
            real_checkboxes_names: function (n) {
                return [(&quot;check_&quot; + (n[0].id || Math.ceil(Math.random() * 10000))), n[0].id]
            }
        },
        plugins: [&quot;themes&quot;, &quot;json_data&quot;, &quot;ui&quot;, &quot;checkbox&quot;]
    });
});
</pre><br />
Now when we submit our form, we should see the ids of the values which were checked:</p>
<p><a href="http://mattfrear.files.wordpress.com/2010/05/submitted.jpg"><img class="aligncenter size-full wp-image-136" title="submitted" src="http://mattfrear.files.wordpress.com/2010/05/submitted.jpg?w=500" alt=""   /></a></p>
<h4><a name="precheck"></a>What about telling the tree to pre-check some items?</h4>
<p>So how do we render the tree with some items already checked? Notice how we added &#8220;public bool selected&#8221; to JsTreeAttribute? This doesn&#8217;t do anything as far as the checkboxes are concerned, but it does add a custom property called &#8220;selected&#8221; to each node&#8217;s &lt;li&gt;. We can use that to tell the jsTree to check the given node, by binding to the &#8216;loaded.jstree&#8217; event.</p>
<p>Scripts/index.js</p>
<p><pre class="brush: jscript; highlight: [13,14];">
$(function () {
    $(&quot;#demoTree&quot;).jstree({
        json_data: {
            data: treeModel
        },
        checkbox: {
            real_checkboxes: true,
            real_checkboxes_names: function (n) {
                return [(&quot;check_&quot; + (n[0].id || Math.ceil(Math.random() * 10000))), n[0].id]
            }
        },
        plugins: [&quot;themes&quot;, &quot;json_data&quot;, &quot;ui&quot;, &quot;checkbox&quot;]
    }).bind(&quot;loaded.jstree&quot;, function (event, data) {
        $('#demoTree').jstree('check_node', 'li[selected=selected]');
    });
});
</pre><br />
You’ll see that the nodes that are marked with selected=true in GetTreeData() are now pre-checked when you first load the page.</p>
<p>Here’s a link to <a href="https://docs.google.com/open?id=0B42kzPRjIqOkNTFmZDdmOGMtNDUxYi00MDE1LWI2MjItZDdhYTk1MzBlODA1">the solution</a> (VS 2010).</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/mattfrear.wordpress.com/481/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/mattfrear.wordpress.com/481/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/mattfrear.wordpress.com/481/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/mattfrear.wordpress.com/481/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/mattfrear.wordpress.com/481/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/mattfrear.wordpress.com/481/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/mattfrear.wordpress.com/481/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/mattfrear.wordpress.com/481/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/mattfrear.wordpress.com/481/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/mattfrear.wordpress.com/481/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/mattfrear.wordpress.com/481/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/mattfrear.wordpress.com/481/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/mattfrear.wordpress.com/481/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/mattfrear.wordpress.com/481/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mattfrear.com&amp;blog=12300335&amp;post=481&amp;subd=mattfrear&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://mattfrear.com/2011/12/17/jstree-revisited/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/5da3065d9a83a23a90c18a5e7d20b180?s=96&#38;d=http%3A%2F%2F1.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">mattfrear</media:title>
		</media:content>

		<media:content url="http://mattfrear.files.wordpress.com/2010/05/jstree.jpg" medium="image">
			<media:title type="html">jstree</media:title>
		</media:content>

		<media:content url="http://mattfrear.files.wordpress.com/2011/12/jstree-files.png" medium="image">
			<media:title type="html">jstree files</media:title>
		</media:content>

		<media:content url="http://mattfrear.files.wordpress.com/2010/05/submitted.jpg" medium="image">
			<media:title type="html">submitted</media:title>
		</media:content>
	</item>
		<item>
		<title>Running a Win 7 VM on a Macbook Air (2011)</title>
		<link>http://mattfrear.com/2011/08/06/running-a-win-7-vm-on-a-macbook-air-2011/</link>
		<comments>http://mattfrear.com/2011/08/06/running-a-win-7-vm-on-a-macbook-air-2011/#comments</comments>
		<pubDate>Sat, 06 Aug 2011 22:24:15 +0000</pubDate>
		<dc:creator>mattfrear</dc:creator>
				<category><![CDATA[Tech support]]></category>

		<guid isPermaLink="false">http://mattfrear.com/?p=473</guid>
		<description><![CDATA[A few days ago I bought a new Macbook Air. I went for the fully pimped one which comes with an i7 and a 256Gb SSD. With the VMware Fusion demo I was able to bring my old laptop over and run it as a VM inside the Mac. A few notes: 1. VMware&#8217;s Migration <a href="http://mattfrear.com/2011/08/06/running-a-win-7-vm-on-a-macbook-air-2011/" class="excerpt-more-link">[&#8230;]</a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mattfrear.com&amp;blog=12300335&amp;post=473&amp;subd=mattfrear&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>A few days ago I bought a new Macbook Air. I went for the fully pimped one which comes with an i7 and a 256Gb SSD. With the VMware Fusion demo I was able to bring my old laptop over and run it as a VM inside the Mac.</p>
<p>A few notes:</p>
<p>1. VMware&#8217;s Migration Assistant wanted to create a VM of my entire laptop, with both C: and D: disks. I didn&#8217;t want to bring over the 200Gb D: and the Migration Assistant didn&#8217;t have any options to prevent that from happening. So on my old laptop, I installed VMware&#8217;s free VMware converter. That had many more options including the option to exclude D:</p>
<p>2. It looks like I don&#8217;t need to buy a new Windows license. So far my VM hasn&#8217;t phoned home to Microsoft &#8211; maybe it will?</p>
<p>3. For networking, although I&#8217;m connected on WiFi to my flat&#8217;s network on the Mac, the VM sees it as an ethernet connection. Initially I couldn&#8217;t connect to the network on the VM because it was complaining that there were no ethernet drivers installed. I had to edit the .vmx file and add a line ethernet0.virtualDEV = &#8220;e1000&#8243;.</p>
<p>4. Visual Studio is completely red and unusable! I haven&#8217;t figured that one out yet.</p>
<p><a href="http://mattfrear.files.wordpress.com/2011/08/visual-studio-red.jpg"><img class="aligncenter size-full wp-image-474" title="visual studio red" src="http://mattfrear.files.wordpress.com/2011/08/visual-studio-red.jpg?w=500&#038;h=326" alt="" width="500" height="326" /></a></p>
<p><strong>Update (Dec 2011)</strong></p>
<p>The Visual Studio red problem I had was with VMWare Fusion 3 and Parallels 6, but it seems to be fixed in VMWare Fusion 4 and Parallels 7. Having said that, I don&#8217;t use virtualisation and reboot and run Win7 in Boot Camp.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/mattfrear.wordpress.com/473/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/mattfrear.wordpress.com/473/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/mattfrear.wordpress.com/473/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/mattfrear.wordpress.com/473/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/mattfrear.wordpress.com/473/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/mattfrear.wordpress.com/473/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/mattfrear.wordpress.com/473/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/mattfrear.wordpress.com/473/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/mattfrear.wordpress.com/473/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/mattfrear.wordpress.com/473/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/mattfrear.wordpress.com/473/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/mattfrear.wordpress.com/473/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/mattfrear.wordpress.com/473/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/mattfrear.wordpress.com/473/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mattfrear.com&amp;blog=12300335&amp;post=473&amp;subd=mattfrear&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://mattfrear.com/2011/08/06/running-a-win-7-vm-on-a-macbook-air-2011/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/5da3065d9a83a23a90c18a5e7d20b180?s=96&#38;d=http%3A%2F%2F1.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">mattfrear</media:title>
		</media:content>

		<media:content url="http://mattfrear.files.wordpress.com/2011/08/visual-studio-red.jpg" medium="image">
			<media:title type="html">visual studio red</media:title>
		</media:content>
	</item>
		<item>
		<title>Visual Studio 2010 PerfWatson extension</title>
		<link>http://mattfrear.com/2011/07/11/visual-studio-2010-perf-watson/</link>
		<comments>http://mattfrear.com/2011/07/11/visual-studio-2010-perf-watson/#comments</comments>
		<pubDate>Mon, 11 Jul 2011 18:37:29 +0000</pubDate>
		<dc:creator>mattfrear</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[visual studio 2010]]></category>

		<guid isPermaLink="false">http://mattfrear.com/?p=461</guid>
		<description><![CDATA[Today I installed the Visual Studio PerfWatson extension. Briefly, it automatically reports when Visual Studio hangs (for &#62; 2 seconds) to Microsoft so that they can one day fix it. But a nicety is the PerfWatson Monitor extension, which adds a cool little graphic it adds to the bottom of Visual Studio: Since I&#8217;m running <a href="http://mattfrear.com/2011/07/11/visual-studio-2010-perf-watson/" class="excerpt-more-link">[&#8230;]</a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mattfrear.com&amp;blog=12300335&amp;post=461&amp;subd=mattfrear&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Today I installed the Visual Studio PerfWatson extension. Briefly, it automatically reports when Visual Studio hangs (for &gt; 2 seconds) to Microsoft so that they can one day fix it.</p>
<p>But a nicety is the PerfWatson Monitor extension, which adds a cool little graphic it adds to the bottom of Visual Studio:<br />
<a href="http://mattfrear.files.wordpress.com/2011/07/watson.png"><img class="aligncenter size-full wp-image-462" title="watson" src="http://mattfrear.files.wordpress.com/2011/07/watson.png?w=500" alt=""   /></a></p>
<p>Since I&#8217;m running Visual Studio on my lowely netbook which constantly hangs (i.e. doesn&#8217;t respond for a few seconds), Microsoft will be getting plenty of data from me!</p>
<p>The Perf Watson <a href="http://blogs.msdn.com/b/visualstudio/archive/2011/05/02/perfwatson.aspx">blog is here</a> but if you want to install it just go to Tools -&gt; Extension Manager (in VS) and search for Watson in the Online Gallery. Install Visual Studio PerfWatson and PerfWatson Monitor.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/mattfrear.wordpress.com/461/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/mattfrear.wordpress.com/461/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/mattfrear.wordpress.com/461/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/mattfrear.wordpress.com/461/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/mattfrear.wordpress.com/461/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/mattfrear.wordpress.com/461/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/mattfrear.wordpress.com/461/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/mattfrear.wordpress.com/461/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/mattfrear.wordpress.com/461/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/mattfrear.wordpress.com/461/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/mattfrear.wordpress.com/461/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/mattfrear.wordpress.com/461/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/mattfrear.wordpress.com/461/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/mattfrear.wordpress.com/461/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mattfrear.com&amp;blog=12300335&amp;post=461&amp;subd=mattfrear&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://mattfrear.com/2011/07/11/visual-studio-2010-perf-watson/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/5da3065d9a83a23a90c18a5e7d20b180?s=96&#38;d=http%3A%2F%2F1.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">mattfrear</media:title>
		</media:content>

		<media:content url="http://mattfrear.files.wordpress.com/2011/07/watson.png" medium="image">
			<media:title type="html">watson</media:title>
		</media:content>
	</item>
		<item>
		<title>Unsubscribe fail</title>
		<link>http://mattfrear.com/2011/07/09/unsubscribe-fail/</link>
		<comments>http://mattfrear.com/2011/07/09/unsubscribe-fail/#comments</comments>
		<pubDate>Sat, 09 Jul 2011 11:33:12 +0000</pubDate>
		<dc:creator>mattfrear</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[rant]]></category>

		<guid isPermaLink="false">http://mattfrear.com/?p=459</guid>
		<description><![CDATA[Newsletter Subscription Thank you. matt.frear@gmail.com has now been successfully unsubscribed from the ASOS.com Style Newsletter. – please allow up to 2 weeks for this to take effect. 2 weeks to unsubscribe? Really? Why&#8217;s it take so long?<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mattfrear.com&amp;blog=12300335&amp;post=459&amp;subd=mattfrear&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<blockquote>
<h3>Newsletter Subscription</h3>
<p>Thank you. matt.frear@gmail.com has now been successfully unsubscribed from the ASOS.com Style Newsletter. – please allow up to 2 weeks for this to take effect.</p></blockquote>
<p>2 weeks to unsubscribe? Really? Why&#8217;s it take so long?</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/mattfrear.wordpress.com/459/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/mattfrear.wordpress.com/459/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/mattfrear.wordpress.com/459/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/mattfrear.wordpress.com/459/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/mattfrear.wordpress.com/459/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/mattfrear.wordpress.com/459/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/mattfrear.wordpress.com/459/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/mattfrear.wordpress.com/459/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/mattfrear.wordpress.com/459/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/mattfrear.wordpress.com/459/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/mattfrear.wordpress.com/459/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/mattfrear.wordpress.com/459/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/mattfrear.wordpress.com/459/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/mattfrear.wordpress.com/459/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mattfrear.com&amp;blog=12300335&amp;post=459&amp;subd=mattfrear&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://mattfrear.com/2011/07/09/unsubscribe-fail/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/5da3065d9a83a23a90c18a5e7d20b180?s=96&#38;d=http%3A%2F%2F1.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">mattfrear</media:title>
		</media:content>
	</item>
		<item>
		<title>iTunes sucks balls</title>
		<link>http://mattfrear.com/2011/07/06/itunes-sucks-balls/</link>
		<comments>http://mattfrear.com/2011/07/06/itunes-sucks-balls/#comments</comments>
		<pubDate>Wed, 06 Jul 2011 14:17:05 +0000</pubDate>
		<dc:creator>mattfrear</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[rant]]></category>

		<guid isPermaLink="false">http://mattfrear.com/?p=456</guid>
		<description><![CDATA[Every time I use iTunes, I hate it. And now I have yet another reason to hate it: Oh fuck off, I don&#8217;t believe you. I&#8217;m running 10.2.2 and you&#8217;re telling me that I need to upgrade to the latest version just to stream a video? Bullshit. You&#8217;re making me upgrade because you think you <a href="http://mattfrear.com/2011/07/06/itunes-sucks-balls/" class="excerpt-more-link">[&#8230;]</a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mattfrear.com&amp;blog=12300335&amp;post=456&amp;subd=mattfrear&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Every time I use iTunes, I hate it. And now I have yet another reason to hate it:</p>
<p><a href="http://mattfrear.files.wordpress.com/2011/07/itunes.png"><img class="aligncenter size-full wp-image-457" title="itunes" src="http://mattfrear.files.wordpress.com/2011/07/itunes.png?w=500" alt="itunes upgrade required"   /></a></p>
<p>Oh fuck off, I don&#8217;t believe you. I&#8217;m running 10.2.2 and you&#8217;re telling me that I need to upgrade to the latest version just to stream a video? <em>Bullshit</em>. You&#8217;re making me upgrade because you think you can make me upgrade. Well fuck you, I&#8217;m not going to, so I won&#8217;t bother watching the iTunes Festival performances either.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/mattfrear.wordpress.com/456/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/mattfrear.wordpress.com/456/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/mattfrear.wordpress.com/456/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/mattfrear.wordpress.com/456/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/mattfrear.wordpress.com/456/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/mattfrear.wordpress.com/456/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/mattfrear.wordpress.com/456/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/mattfrear.wordpress.com/456/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/mattfrear.wordpress.com/456/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/mattfrear.wordpress.com/456/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/mattfrear.wordpress.com/456/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/mattfrear.wordpress.com/456/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/mattfrear.wordpress.com/456/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/mattfrear.wordpress.com/456/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mattfrear.com&amp;blog=12300335&amp;post=456&amp;subd=mattfrear&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://mattfrear.com/2011/07/06/itunes-sucks-balls/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/5da3065d9a83a23a90c18a5e7d20b180?s=96&#38;d=http%3A%2F%2F1.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">mattfrear</media:title>
		</media:content>

		<media:content url="http://mattfrear.files.wordpress.com/2011/07/itunes.png" medium="image">
			<media:title type="html">itunes</media:title>
		</media:content>
	</item>
		<item>
		<title>SortedDictionary of countries in the world</title>
		<link>http://mattfrear.com/2011/07/03/sorteddictionary-of-countries-in-the-world/</link>
		<comments>http://mattfrear.com/2011/07/03/sorteddictionary-of-countries-in-the-world/#comments</comments>
		<pubDate>Sun, 03 Jul 2011 22:13:25 +0000</pubDate>
		<dc:creator>mattfrear</dc:creator>
				<category><![CDATA[Code]]></category>

		<guid isPermaLink="false">http://mattfrear.com/?p=449</guid>
		<description><![CDATA[In case you need it &#8211; this might come in handy. A dictionary of all countries in the world with their ISO 3166 two digit country code. SortedDictionary countries = new SortedDictionary { {&#8220;AF&#8221;, &#8220;Afghanistan&#8221;}, {&#8220;AX&#8221;, &#8220;Aland Islands&#8221;}, {&#8220;AL&#8221;, &#8220;Albania&#8221;}, {&#8220;DZ&#8221;, &#8220;Algeria&#8221;}, {&#8220;AS&#8221;, &#8220;American Samoa&#8221;}, {&#8220;AD&#8221;, &#8220;Andorra&#8221;}, {&#8220;AO&#8221;, &#8220;Angola&#8221;}, {&#8220;AI&#8221;, &#8220;Anguilla&#8221;}, {&#8220;AQ&#8221;, &#8220;Antarctica&#8221;}, {&#8220;AG&#8221;, &#8220;Antigua <a href="http://mattfrear.com/2011/07/03/sorteddictionary-of-countries-in-the-world/" class="excerpt-more-link">[&#8230;]</a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mattfrear.com&amp;blog=12300335&amp;post=449&amp;subd=mattfrear&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>In case you need it &#8211; this might come in handy.</p>
<p>A dictionary of all countries in the world with their ISO 3166 two digit country code.</p>
<pre><span class="Apple-style-span" style="font-family:Georgia, 'Times New Roman', 'Bitstream Charter', Times, serif;font-size:13px;line-height:19px;white-space:normal;">SortedDictionary countries = new SortedDictionary {</span></pre>
<p>{&#8220;AF&#8221;, &#8220;Afghanistan&#8221;},<br />
{&#8220;AX&#8221;, &#8220;Aland Islands&#8221;},<br />
{&#8220;AL&#8221;, &#8220;Albania&#8221;},<br />
{&#8220;DZ&#8221;, &#8220;Algeria&#8221;},<br />
{&#8220;AS&#8221;, &#8220;American Samoa&#8221;},<br />
{&#8220;AD&#8221;, &#8220;Andorra&#8221;},<br />
{&#8220;AO&#8221;, &#8220;Angola&#8221;},<br />
{&#8220;AI&#8221;, &#8220;Anguilla&#8221;},<br />
{&#8220;AQ&#8221;, &#8220;Antarctica&#8221;},<br />
{&#8220;AG&#8221;, &#8220;Antigua and Barbuda&#8221;},<br />
{&#8220;AR&#8221;, &#8220;Argentina&#8221;},<br />
{&#8220;AM&#8221;, &#8220;Armenia&#8221;},<br />
{&#8220;AW&#8221;, &#8220;Aruba&#8221;},<br />
{&#8220;AU&#8221;, &#8220;Australia&#8221;},<br />
{&#8220;AT&#8221;, &#8220;Austria&#8221;},<br />
{&#8220;AZ&#8221;, &#8220;Azerbaijan&#8221;},<br />
{&#8220;BS&#8221;, &#8220;Bahamas&#8221;},<br />
{&#8220;BH&#8221;, &#8220;Bahrain&#8221;},<br />
{&#8220;BD&#8221;, &#8220;Bangladesh&#8221;},<br />
{&#8220;BB&#8221;, &#8220;Barbados&#8221;},<br />
{&#8220;BY&#8221;, &#8220;Belarus&#8221;},<br />
{&#8220;BE&#8221;, &#8220;Belgium&#8221;},<br />
{&#8220;BZ&#8221;, &#8220;Belize&#8221;},<br />
{&#8220;BJ&#8221;, &#8220;Benin&#8221;},<br />
{&#8220;BM&#8221;, &#8220;Bermuda&#8221;},<br />
{&#8220;BT&#8221;, &#8220;Bhutan&#8221;},<br />
{&#8220;BO&#8221;, &#8220;Bolivia &#8220;},<br />
{&#8220;BQ&#8221;, &#8220;Bonaire&#8221;},<br />
{&#8220;BA&#8221;, &#8220;Bosnia and Herzegovina&#8221;},<br />
{&#8220;BW&#8221;, &#8220;Botswana&#8221;},<br />
{&#8220;BV&#8221;, &#8220;Bouvet Island&#8221;},<br />
{&#8220;BR&#8221;, &#8220;Brazil&#8221;},<br />
{&#8220;IO&#8221;, &#8220;British indian Ocean Territory&#8221;},<br />
{&#8220;BN&#8221;, &#8220;Brunei Darussalam&#8221;},<br />
{&#8220;BG&#8221;, &#8220;Bulgaria&#8221;},<br />
{&#8220;BF&#8221;, &#8220;Burkina Faso&#8221;},<br />
{&#8220;BI&#8221;, &#8220;Burundi&#8221;},<br />
{&#8220;KH&#8221;, &#8220;Cambodia&#8221;},<br />
{&#8220;CM&#8221;, &#8220;Cameroon&#8221;},<br />
{&#8220;CA&#8221;, &#8220;Canada&#8221;},<br />
{&#8220;CV&#8221;, &#8220;Cape Verde&#8221;},<br />
{&#8220;KY&#8221;, &#8220;Cayman Islands&#8221;},<br />
{&#8220;CF&#8221;, &#8220;Central African Republic&#8221;},<br />
{&#8220;TD&#8221;, &#8220;Chad&#8221;},<br />
{&#8220;CL&#8221;, &#8220;Chile&#8221;},<br />
{&#8220;CN&#8221;, &#8220;China&#8221;},<br />
{&#8220;CX&#8221;, &#8220;Christmas Island&#8221;},<br />
{&#8220;CC&#8221;, &#8220;Cocos (keeling) Islands&#8221;},<br />
{&#8220;CO&#8221;, &#8220;Colombia&#8221;},<br />
{&#8220;KM&#8221;, &#8220;Comoros&#8221;},<br />
{&#8220;CG&#8221;, &#8220;Congo&#8221;},<br />
{&#8220;CD&#8221;, &#8220;Congo, The Democratic Republic of the&#8221;},<br />
{&#8220;CK&#8221;, &#8220;Cook Islands&#8221;},<br />
{&#8220;CR&#8221;, &#8220;Costa Rica&#8221;},<br />
{&#8220;CI&#8221;, &#8220;Cote d&#8217;Ivoire&#8221;},<br />
{&#8220;HR&#8221;, &#8220;Croatia&#8221;},<br />
{&#8220;CU&#8221;, &#8220;Cuba&#8221;},<br />
{&#8220;CW&#8221;, &#8220;Curacao&#8221;},<br />
{&#8220;CY&#8221;, &#8220;Cyprus&#8221;},<br />
{&#8220;CZ&#8221;, &#8220;Czech Republic&#8221;},<br />
{&#8220;DK&#8221;, &#8220;Denmark&#8221;},<br />
{&#8220;DJ&#8221;, &#8220;Djibouti&#8221;},<br />
{&#8220;DM&#8221;, &#8220;Dominica&#8221;},<br />
{&#8220;DO&#8221;, &#8220;Dominican Republic&#8221;},<br />
{&#8220;EC&#8221;, &#8220;Ecuador&#8221;},<br />
{&#8220;EG&#8221;, &#8220;Egypt&#8221;},<br />
{&#8220;SV&#8221;, &#8220;El salvador&#8221;},<br />
{&#8220;GQ&#8221;, &#8220;Equatorial guinea&#8221;},<br />
{&#8220;ER&#8221;, &#8220;Eritrea&#8221;},<br />
{&#8220;EE&#8221;, &#8220;Estonia&#8221;},<br />
{&#8220;ET&#8221;, &#8220;Ethiopia&#8221;},<br />
{&#8220;FK&#8221;, &#8220;Falkland Islands (Malvinas)&#8221;},<br />
{&#8220;FO&#8221;, &#8220;Faroe Islands&#8221;},<br />
{&#8220;FJ&#8221;, &#8220;Fiji&#8221;},<br />
{&#8220;FI&#8221;, &#8220;Finland&#8221;},<br />
{&#8220;FR&#8221;, &#8220;France&#8221;},<br />
{&#8220;GF&#8221;, &#8220;French Guiana&#8221;},<br />
{&#8220;PF&#8221;, &#8220;French Polynesia&#8221;},<br />
{&#8220;TF&#8221;, &#8220;French Southern Territories&#8221;},<br />
{&#8220;GA&#8221;, &#8220;Gabon&#8221;},<br />
{&#8220;GM&#8221;, &#8220;Gambia&#8221;},<br />
{&#8220;GE&#8221;, &#8220;Georgia&#8221;},<br />
{&#8220;DE&#8221;, &#8220;Germany&#8221;},<br />
{&#8220;GH&#8221;, &#8220;Ghana&#8221;},<br />
{&#8220;GI&#8221;, &#8220;Gibraltar&#8221;},<br />
{&#8220;GR&#8221;, &#8220;Greece&#8221;},<br />
{&#8220;GL&#8221;, &#8220;Greenland&#8221;},<br />
{&#8220;GD&#8221;, &#8220;Grenada&#8221;},<br />
{&#8220;GP&#8221;, &#8220;Guadeloupe&#8221;},<br />
{&#8220;GU&#8221;, &#8220;Guam&#8221;},<br />
{&#8220;GT&#8221;, &#8220;Guatemala&#8221;},<br />
{&#8220;GG&#8221;, &#8220;Guernsey&#8221;},<br />
{&#8220;GN&#8221;, &#8220;Guinea&#8221;},<br />
{&#8220;GW&#8221;, &#8220;Guinea-Bissau&#8221;},<br />
{&#8220;GY&#8221;, &#8220;Guyana&#8221;},<br />
{&#8220;HT&#8221;, &#8220;Haiti&#8221;},<br />
{&#8220;HM&#8221;, &#8220;Heard Island and Mcdonald Islands&#8221;},<br />
{&#8220;HN&#8221;, &#8220;Honduras&#8221;},<br />
{&#8220;HK&#8221;, &#8220;Hong Kong&#8221;},<br />
{&#8220;HU&#8221;, &#8220;Hungary&#8221;},<br />
{&#8220;IS&#8221;, &#8220;Iceland&#8221;},<br />
{&#8220;IN&#8221;, &#8220;India&#8221;},<br />
{&#8220;ID&#8221;, &#8220;Indonesia&#8221;},<br />
{&#8220;IR&#8221;, &#8220;Iran,&#8221;},<br />
{&#8220;IQ&#8221;, &#8220;Iraq&#8221;},<br />
{&#8220;IE&#8221;, &#8220;Ireland&#8221;},<br />
{&#8220;IM&#8221;, &#8220;Isle of Man&#8221;},<br />
{&#8220;IL&#8221;, &#8220;Israel&#8221;},<br />
{&#8220;IT&#8221;, &#8220;Italy&#8221;},<br />
{&#8220;JM&#8221;, &#8220;Jamaica&#8221;},<br />
{&#8220;JP&#8221;, &#8220;Japan&#8221;},<br />
{&#8220;JE&#8221;, &#8220;Jersey&#8221;},<br />
{&#8220;JO&#8221;, &#8220;Jordan&#8221;},<br />
{&#8220;KZ&#8221;, &#8220;Kazakhstan&#8221;},<br />
{&#8220;KE&#8221;, &#8220;Kenya&#8221;},<br />
{&#8220;KI&#8221;, &#8220;Kiribati&#8221;},<br />
{&#8220;KP&#8221;, &#8220;Korea, Democratic People&#8217;s Republic of&#8221;},<br />
{&#8220;KR&#8221;, &#8220;Korea, Republic of&#8221;},<br />
{&#8220;KW&#8221;, &#8220;Kuwait&#8221;},<br />
{&#8220;KG&#8221;, &#8220;Kyrgyzstan&#8221;},<br />
{&#8220;LA&#8221;, &#8220;Lao People&#8217;s Democratic Republic&#8221;},<br />
{&#8220;LV&#8221;, &#8220;Latvia&#8221;},<br />
{&#8220;LB&#8221;, &#8220;Lebanon&#8221;},<br />
{&#8220;LS&#8221;, &#8220;Lesotho&#8221;},<br />
{&#8220;LR&#8221;, &#8220;Liberia&#8221;},<br />
{&#8220;LY&#8221;, &#8220;Libya&#8221;},<br />
{&#8220;LI&#8221;, &#8220;Liechtenstein&#8221;},<br />
{&#8220;LT&#8221;, &#8220;Lithuania&#8221;},<br />
{&#8220;LU&#8221;, &#8220;Luxembourg&#8221;},<br />
{&#8220;MO&#8221;, &#8220;Macao&#8221;},<br />
{&#8220;MK&#8221;, &#8220;Macedonia,&#8221;},<br />
{&#8220;MG&#8221;, &#8220;Madagascar&#8221;},<br />
{&#8220;MW&#8221;, &#8220;Malawi&#8221;},<br />
{&#8220;MY&#8221;, &#8220;Malaysia&#8221;},<br />
{&#8220;MV&#8221;, &#8220;Maldives&#8221;},<br />
{&#8220;ML&#8221;, &#8220;Mali&#8221;},<br />
{&#8220;MT&#8221;, &#8220;Malta&#8221;},<br />
{&#8220;MH&#8221;, &#8220;Marshall Islands&#8221;},<br />
{&#8220;MQ&#8221;, &#8220;Martinique&#8221;},<br />
{&#8220;MR&#8221;, &#8220;Mauritania&#8221;},<br />
{&#8220;MU&#8221;, &#8220;Mauritius&#8221;},<br />
{&#8220;YT&#8221;, &#8220;Mayotte&#8221;},<br />
{&#8220;MX&#8221;, &#8220;Mexico&#8221;},<br />
{&#8220;FM&#8221;, &#8220;Micronesia,&#8221;},<br />
{&#8220;MD&#8221;, &#8220;Moldova, Republic of&#8221;},<br />
{&#8220;MC&#8221;, &#8220;Monaco&#8221;},<br />
{&#8220;MN&#8221;, &#8220;Mongolia&#8221;},<br />
{&#8220;ME&#8221;, &#8220;Montenegro&#8221;},<br />
{&#8220;MS&#8221;, &#8220;Montserrat&#8221;},<br />
{&#8220;MA&#8221;, &#8220;Morocco&#8221;},<br />
{&#8220;MZ&#8221;, &#8220;Mozambique&#8221;},<br />
{&#8220;MM&#8221;, &#8220;Myanmar&#8221;},<br />
{&#8220;NA&#8221;, &#8220;Namibia&#8221;},<br />
{&#8220;NR&#8221;, &#8220;Nauru&#8221;},<br />
{&#8220;NP&#8221;, &#8220;Nepal&#8221;},<br />
{&#8220;NL&#8221;, &#8220;Netherlands&#8221;},<br />
{&#8220;NC&#8221;, &#8220;New Caledonia&#8221;},<br />
{&#8220;NZ&#8221;, &#8220;New Zealand&#8221;},<br />
{&#8220;NI&#8221;, &#8220;Nicaragua&#8221;},<br />
{&#8220;NE&#8221;, &#8220;Niger&#8221;},<br />
{&#8220;NG&#8221;, &#8220;Nigeria&#8221;},<br />
{&#8220;NU&#8221;, &#8220;Niue&#8221;},<br />
{&#8220;NF&#8221;, &#8220;Norfolk Island&#8221;},<br />
{&#8220;MP&#8221;, &#8220;Northern Mariana Islands&#8221;},<br />
{&#8220;NO&#8221;, &#8220;Norway&#8221;},<br />
{&#8220;OM&#8221;, &#8220;Oman&#8221;},<br />
{&#8220;PK&#8221;, &#8220;Pakistan&#8221;},<br />
{&#8220;PW&#8221;, &#8220;Palau&#8221;},<br />
{&#8220;PS&#8221;, &#8220;Palestinian Territory, Occupied&#8221;},<br />
{&#8220;PA&#8221;, &#8220;Panama&#8221;},<br />
{&#8220;PG&#8221;, &#8220;Papua New Guinea&#8221;},<br />
{&#8220;PY&#8221;, &#8220;Paraguay&#8221;},<br />
{&#8220;PE&#8221;, &#8220;Peru&#8221;},<br />
{&#8220;PH&#8221;, &#8220;Philippines&#8221;},<br />
{&#8220;PN&#8221;, &#8220;Pitcairn&#8221;},<br />
{&#8220;PL&#8221;, &#8220;Poland&#8221;},<br />
{&#8220;PT&#8221;, &#8220;Portugal&#8221;},<br />
{&#8220;PR&#8221;, &#8220;Puerto Rico&#8221;},<br />
{&#8220;QA&#8221;, &#8220;Qatar&#8221;},<br />
{&#8220;RE&#8221;, &#8220;Reunion&#8221;},<br />
{&#8220;RO&#8221;, &#8220;Romania&#8221;},<br />
{&#8220;RU&#8221;, &#8220;Russian Federation&#8221;},<br />
{&#8220;RW&#8221;, &#8220;Rwanda&#8221;},<br />
{&#8220;BL&#8221;, &#8220;Saint Barthelemy&#8221;},<br />
{&#8220;SH&#8221;, &#8220;Saint Helena,&#8221;},<br />
{&#8220;KN&#8221;, &#8220;Saint Kitts and Nevis&#8221;},<br />
{&#8220;LC&#8221;, &#8220;Saint Lucia&#8221;},<br />
{&#8220;MF&#8221;, &#8220;Saint Martin (French Part)&#8221;},<br />
{&#8220;PM&#8221;, &#8220;Saint Pierre and Miquelon&#8221;},<br />
{&#8220;VC&#8221;, &#8220;Saint Vincent and the Grenadines&#8221;},<br />
{&#8220;WS&#8221;, &#8220;Samoa&#8221;},<br />
{&#8220;SM&#8221;, &#8220;San Marino&#8221;},<br />
{&#8220;ST&#8221;, &#8220;Sao Tome and Principe&#8221;},<br />
{&#8220;SA&#8221;, &#8220;Saudi Arabia&#8221;},<br />
{&#8220;SN&#8221;, &#8220;Senegal&#8221;},<br />
{&#8220;RS&#8221;, &#8220;Serbia&#8221;},<br />
{&#8220;SC&#8221;, &#8220;Seychelles&#8221;},<br />
{&#8220;SL&#8221;, &#8220;Sierra Leone&#8221;},<br />
{&#8220;SG&#8221;, &#8220;Singapore&#8221;},<br />
{&#8220;SX&#8221;, &#8220;Sint Maarten (Dutch part)&#8221;},<br />
{&#8220;SK&#8221;, &#8220;Slovakia&#8221;},<br />
{&#8220;SI&#8221;, &#8220;Slovenia&#8221;},<br />
{&#8220;SB&#8221;, &#8220;Solomon Islands&#8221;},<br />
{&#8220;SO&#8221;, &#8220;Somalia&#8221;},<br />
{&#8220;ZA&#8221;, &#8220;South africa&#8221;},<br />
{&#8220;GS&#8221;, &#8220;South Georgia and the South Sandwich Islands&#8221;},<br />
{&#8220;ES&#8221;, &#8220;Spain&#8221;},<br />
{&#8220;LK&#8221;, &#8220;Sri Lanka&#8221;},<br />
{&#8220;SD&#8221;, &#8220;Sudan&#8221;},<br />
{&#8220;SR&#8221;, &#8220;Suriname&#8221;},<br />
{&#8220;SJ&#8221;, &#8220;Svalbard and Jan Mayen&#8221;},<br />
{&#8220;SZ&#8221;, &#8220;Swaziland&#8221;},<br />
{&#8220;SE&#8221;, &#8220;Sweden&#8221;},<br />
{&#8220;CH&#8221;, &#8220;Switzerland&#8221;},<br />
{&#8220;SY&#8221;, &#8220;Syrian Arab Republic&#8221;},<br />
{&#8220;TW&#8221;, &#8220;Taiwan, Province of China&#8221;},<br />
{&#8220;TJ&#8221;, &#8220;Tajikistan&#8221;},<br />
{&#8220;TZ&#8221;, &#8220;Tanzania,&#8221;},<br />
{&#8220;TH&#8221;, &#8220;Thailand&#8221;},<br />
{&#8220;TL&#8221;, &#8220;Timor-leste&#8221;},<br />
{&#8220;TG&#8221;, &#8220;Togo&#8221;},<br />
{&#8220;TK&#8221;, &#8220;Tokelau&#8221;},<br />
{&#8220;TO&#8221;, &#8220;Tonga&#8221;},<br />
{&#8220;TT&#8221;, &#8220;Trinidad and Tobago&#8221;},<br />
{&#8220;TN&#8221;, &#8220;Tunisia&#8221;},<br />
{&#8220;TR&#8221;, &#8220;Turkey&#8221;},<br />
{&#8220;TM&#8221;, &#8220;Turkmenistan&#8221;},<br />
{&#8220;TC&#8221;, &#8220;Turks and Caicos Islands&#8221;},<br />
{&#8220;TV&#8221;, &#8220;Tuvalu&#8221;},<br />
{&#8220;UG&#8221;, &#8220;Uganda&#8221;},<br />
{&#8220;UA&#8221;, &#8220;Ukraine&#8221;},<br />
{&#8220;AE&#8221;, &#8220;United Arab Emirates&#8221;},<br />
{&#8220;GB&#8221;, &#8220;United Kingdom&#8221;},<br />
{&#8220;US&#8221;, &#8220;United States&#8221;},<br />
{&#8220;UM&#8221;, &#8220;United States Minor Outlying Islands&#8221;},<br />
{&#8220;UY&#8221;, &#8220;Uruguay&#8221;},<br />
{&#8220;UZ&#8221;, &#8220;Uzbekistan&#8221;},<br />
{&#8220;VU&#8221;, &#8220;Vanuatu&#8221;},<br />
{&#8220;VA&#8221;, &#8220;Vatican City State&#8221;},<br />
{&#8220;VE&#8221;, &#8220;Venezuela,&#8221;},<br />
{&#8220;VN&#8221;, &#8220;Vietnam&#8221;},<br />
{&#8220;VG&#8221;, &#8220;Virgin Islands, British&#8221;},<br />
{&#8220;VI&#8221;, &#8220;Virgin Islands, U.S.&#8221;},<br />
{&#8220;WF&#8221;, &#8220;Wallis and Futuna&#8221;},<br />
{&#8220;EH&#8221;, &#8220;Western Sahara&#8221;},<br />
{&#8220;YE&#8221;, &#8220;Yemen&#8221;},<br />
{&#8220;ZM&#8221;, &#8220;Zambia&#8221;},<br />
{&#8220;ZW&#8221;, &#8220;Zimbabwe&#8221;}<br />
};</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/mattfrear.wordpress.com/449/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/mattfrear.wordpress.com/449/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/mattfrear.wordpress.com/449/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/mattfrear.wordpress.com/449/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/mattfrear.wordpress.com/449/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/mattfrear.wordpress.com/449/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/mattfrear.wordpress.com/449/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/mattfrear.wordpress.com/449/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/mattfrear.wordpress.com/449/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/mattfrear.wordpress.com/449/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/mattfrear.wordpress.com/449/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/mattfrear.wordpress.com/449/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/mattfrear.wordpress.com/449/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/mattfrear.wordpress.com/449/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mattfrear.com&amp;blog=12300335&amp;post=449&amp;subd=mattfrear&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://mattfrear.com/2011/07/03/sorteddictionary-of-countries-in-the-world/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/5da3065d9a83a23a90c18a5e7d20b180?s=96&#38;d=http%3A%2F%2F1.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">mattfrear</media:title>
		</media:content>
	</item>
		<item>
		<title>Using EF code first with an mdf database in App_Data</title>
		<link>http://mattfrear.com/2011/05/26/ef-code-first-mdf-database/</link>
		<comments>http://mattfrear.com/2011/05/26/ef-code-first-mdf-database/#comments</comments>
		<pubDate>Thu, 26 May 2011 17:23:43 +0000</pubDate>
		<dc:creator>mattfrear</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[ef code-first]]></category>

		<guid isPermaLink="false">http://mattfrear.com/?p=443</guid>
		<description><![CDATA[I&#8217;ve been playing around some more with EF code first. Today&#8217;s task was to try to get it to work with a .mdf file located in the App_Data folder of the web project. It wasn&#8217;t much fun. I hijacked the existing aspnetdb.mdf and tried to get that to work with EF Code First. Short answer: <a href="http://mattfrear.com/2011/05/26/ef-code-first-mdf-database/" class="excerpt-more-link">[&#8230;]</a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mattfrear.com&amp;blog=12300335&amp;post=443&amp;subd=mattfrear&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been playing around some more with EF code first. Today&#8217;s task was to try to get it to work with a .mdf file located in the App_Data folder of the web project.</p>
<p>It wasn&#8217;t much fun.</p>
<p>I hijacked the existing aspnetdb.mdf and tried to get that to work with EF Code First. Short answer: don&#8217;t bother, for these reasons:</p>
<ol>
<li>I couldn&#8217;t get EF code first to create my Category table</li>
<li>So then I&#8217;d created the table manually myself in SQL Server Express, but EF still wouldn&#8217;t recognise it &#8211; &#8220;Invalid object name dbo.Category&#8221;</li>
<li>So then I decided to start with a new .mdf file and yay EF code first created my Category table</li>
<li>run aspnet_regsql.exe on it to get the ASP.NET Membership tables in there &#8211; fail</li>
<li>Visual Studio has a lock on the mdf file &#8211; delete it from VS&#8217;s Server Explorer, run aspnet_regsql, yay</li>
<li>Open DB in SQL Server Management studio to see what my database looks like &#8211; fail, locks on file</li>
</ol>
<p>I&#8217;m not sure how to debug EF code first, I mean if it doesn&#8217;t work (i.e. your table isn&#8217;t created) you have no idea why.</p>
<p>So I guess I got it working in the end, but all the problems with the files being locked made me realise it&#8217;s not worth the hassle so I started again with a normal database inside SQL Express.</p>
<ol>
<li>Add your connection string: </li>
</ol>
<p><pre class="brush: csharp;">
    &lt;add name=&quot;SiteDB&quot; 
         connectionString=&quot;data source=.\SQLEXPRESS;Initial Catalog=Site;Integrated Security=SSPI;&quot;
         providerName=&quot;System.Data.SqlClient&quot; /&gt;
</pre><br />
I recommend explicitly setting a connection string otherwise your database will have a big silly namespaced name. You don&#8217;t need to create the database though, EF will do that much for you.</p>
<ol start="2">
<li>Run your app and hit the Categories page so that EF will create the tables</li>
<li>Run aspnet_regsql.exe on it to add the membership tables</li>
<li>Change your membership connection string to point to the same DB &#8211; or tell the AspNetSqlMembership provider to use that connection string blah blah</li>
</ol>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/mattfrear.wordpress.com/443/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/mattfrear.wordpress.com/443/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/mattfrear.wordpress.com/443/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/mattfrear.wordpress.com/443/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/mattfrear.wordpress.com/443/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/mattfrear.wordpress.com/443/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/mattfrear.wordpress.com/443/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/mattfrear.wordpress.com/443/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/mattfrear.wordpress.com/443/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/mattfrear.wordpress.com/443/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/mattfrear.wordpress.com/443/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/mattfrear.wordpress.com/443/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/mattfrear.wordpress.com/443/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/mattfrear.wordpress.com/443/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mattfrear.com&amp;blog=12300335&amp;post=443&amp;subd=mattfrear&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://mattfrear.com/2011/05/26/ef-code-first-mdf-database/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/5da3065d9a83a23a90c18a5e7d20b180?s=96&#38;d=http%3A%2F%2F1.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">mattfrear</media:title>
		</media:content>
	</item>
		<item>
		<title>Announcing MVC3 starter site</title>
		<link>http://mattfrear.com/2011/05/25/mvc3-starter-site/</link>
		<comments>http://mattfrear.com/2011/05/25/mvc3-starter-site/#comments</comments>
		<pubDate>Wed, 25 May 2011 17:58:50 +0000</pubDate>
		<dc:creator>mattfrear</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[asp.net-mvc]]></category>

		<guid isPermaLink="false">http://mattfrear.com/?p=435</guid>
		<description><![CDATA[Inspired by Rob Conery&#8217;s MVC starter site, I&#8217;ve created an MVC3 starter site. It basically takes Visual Studio&#8217;s File -&#62; New Project -&#62; ASP.NET MVC 3 Web Application and builds on that, adding all the things we need to get started &#8211; IOC (Unity), Unit of work pattern, Logging (NLog), Reporting, oh and some CSS <a href="http://mattfrear.com/2011/05/25/mvc3-starter-site/" class="excerpt-more-link">[&#8230;]</a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mattfrear.com&amp;blog=12300335&amp;post=435&amp;subd=mattfrear&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Inspired by Rob Conery&#8217;s <a href="http://mvcstarter.codeplex.com/">MVC starter site</a>, I&#8217;ve created an <a href="http://mvc3starter.codeplex.com/">MVC3 starter site</a>.</p>
<p>It basically takes Visual Studio&#8217;s File -&gt; New Project -&gt; ASP.NET MVC 3 Web Application and builds on that, adding all the things we need to get started &#8211; IOC (Unity), Unit of work pattern, Logging (NLog), Reporting, oh and some CSS from <a href="http://www.freecsstemplates.org/">freecsstemplates.org</a>.</p>
<p>It&#8217;s also my first open source project in a while&#8230;</p>
<p>You can download it from codeplex at <a href="http://mvc3starter.codeplex.com/">http://mvc3starter.codeplex.com<br />
<a href="http://mattfrear.files.wordpress.com/2011/05/mvc3.png"></p>
<p><img src="http://mattfrear.files.wordpress.com/2011/05/mvc3.png?w=500&#038;h=295" alt="mvc3 starter app screenshot" title="mvc3" width="500" height="295" class="aligncenter size-full wp-image-436" /></a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/mattfrear.wordpress.com/435/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/mattfrear.wordpress.com/435/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/mattfrear.wordpress.com/435/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/mattfrear.wordpress.com/435/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/mattfrear.wordpress.com/435/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/mattfrear.wordpress.com/435/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/mattfrear.wordpress.com/435/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/mattfrear.wordpress.com/435/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/mattfrear.wordpress.com/435/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/mattfrear.wordpress.com/435/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/mattfrear.wordpress.com/435/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/mattfrear.wordpress.com/435/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/mattfrear.wordpress.com/435/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/mattfrear.wordpress.com/435/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mattfrear.com&amp;blog=12300335&amp;post=435&amp;subd=mattfrear&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://mattfrear.com/2011/05/25/mvc3-starter-site/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/5da3065d9a83a23a90c18a5e7d20b180?s=96&#38;d=http%3A%2F%2F1.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">mattfrear</media:title>
		</media:content>

		<media:content url="http://mattfrear.files.wordpress.com/2011/05/mvc3.png" medium="image">
			<media:title type="html">mvc3</media:title>
		</media:content>
	</item>
		<item>
		<title>Organise your digital life &#8211; Part 1 Photos</title>
		<link>http://mattfrear.com/2011/05/05/organise-your-digital-life-part-1-photos/</link>
		<comments>http://mattfrear.com/2011/05/05/organise-your-digital-life-part-1-photos/#comments</comments>
		<pubDate>Thu, 05 May 2011 20:46:35 +0000</pubDate>
		<dc:creator>mattfrear</dc:creator>
				<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://mattfrear.com/?p=421</guid>
		<description><![CDATA[I got my first digital camera in 1998. It was a low-end Kodak model but it was still quite expensive, around US$200, and it took photos at a whopping 493&#215;373 resolution. I think it held about 20 photos in it&#8217;s internal memory. It didn&#8217;t even have a flash! Back then I didn&#8217;t have much of <a href="http://mattfrear.com/2011/05/05/organise-your-digital-life-part-1-photos/" class="excerpt-more-link">[&#8230;]</a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mattfrear.com&amp;blog=12300335&amp;post=421&amp;subd=mattfrear&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I got my first digital camera in 1998. It was a low-end Kodak model but it was still quite expensive, around US$200, and it took photos at a whopping 493&#215;373 resolution. I think it held about 20 photos in it&#8217;s internal memory. It didn&#8217;t even have a flash!</p>
<p>Back then I didn&#8217;t have much of a strategy for organising my digital photos &#8211; and the photos were so crap I didn&#8217;t use it all that often anyway:<br />
<a href="http://mattfrear.files.wordpress.com/2011/05/my-workspace.jpg"><img src="http://mattfrear.files.wordpress.com/2011/05/my-workspace.jpg?w=500" alt="" title="My Workspace"   class="aligncenter size-full wp-image-427" /></a><br />
<em>My student workspace in 1998, taken on my 1998 era Kodak digital camera. Spray-painted keyboard and spray-painted big-ass server case, oh yeah. Looks like the 14&#8243; monitor is running Winamp.</em></p>
<p>My next digital camera was in 2003 &#8211; a <a href="http://www.dpreview.com/reviews/pentaxoptios/">Pentax Optio S</a>, the original &#8220;Altoids tin&#8221; camera. This camera served me well and I still have it lying around somewhere. Alas the flimsy battery compartment lid broke off but other than that it still works.</p>
<p><img src="http://a.img-dpreview.com/reviews/PentaxOptioS/Images/frontview-001.jpg" alt="Pentax Optio S" /></p>
<p>Anyway, about 2004 I realised I needed a strategy for organising all of my photos, and the strategy I chose and which have stuck to is this.</p>
<p>Under My Pictures I have a Camera folder. In the Camera folder is a folder for each year:<br />
<a href="http://mattfrear.files.wordpress.com/2011/05/camera.png"><img src="http://mattfrear.files.wordpress.com/2011/05/camera.png?w=500&#038;h=351" alt="" title="camera folder" width="500" height="351" class="aligncenter size-full wp-image-423" /></a></p>
<p>Each year is divided up into sub-folders named after the locations where I have taken photos.<br />
<a href="http://mattfrear.files.wordpress.com/2011/05/2010.png"><img src="http://mattfrear.files.wordpress.com/2011/05/2010.png?w=500&#038;h=351" alt="" title="2010" width="500" height="351" class="aligncenter size-full wp-image-424" /></a></p>
<p>The naming format of each subfolder is &#8220;## &#8211; Place name&#8221;. E.g. in 2010 the first place I took photos was at my friend Kelvin&#8217;s wedding in New Plymouth so that is the first folder listed.</p>
<p>It&#8217;s really quite straightforward (and I think worthwhile) to organise your photos into folders based on year and location.</p>
<p>Finally, at the photos level is where I get a bit more pedantic (and it&#8217;s probably not necessary).<br />
<a href="http://mattfrear.files.wordpress.com/2011/05/london.png"><img src="http://mattfrear.files.wordpress.com/2011/05/london.png?w=500&#038;h=351" alt="" title="london" width="500" height="351" class="aligncenter size-full wp-image-425" /></a><br />
I usually rename my folders &#8220;Event &#8211; ##&#8221; or if the photo contains people then &#8220;Event &#8211; ## &#8211; Person Name&#8221;. I use a tool for renaming the photos in this way (an old version of ACDSee that came bundled with my Pentax camera in 2003) but I still need to manually add my friend&#8217;s names to the filename.</p>
<p>And that&#8217;s it. I know that most people aren&#8217;t going to bother to rename each photo the way I do (fair enough), but I think it&#8217;s not much effort to organise your photos into folders by year and location. And for god&#8217;s sake, delete your crap photos. I am notoriously economical with photos, i.e. I might take 10 or 20 shots of a landmark but I&#8217;ll only keep 1 or 2 of them.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/mattfrear.wordpress.com/421/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/mattfrear.wordpress.com/421/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/mattfrear.wordpress.com/421/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/mattfrear.wordpress.com/421/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/mattfrear.wordpress.com/421/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/mattfrear.wordpress.com/421/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/mattfrear.wordpress.com/421/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/mattfrear.wordpress.com/421/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/mattfrear.wordpress.com/421/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/mattfrear.wordpress.com/421/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/mattfrear.wordpress.com/421/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/mattfrear.wordpress.com/421/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/mattfrear.wordpress.com/421/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/mattfrear.wordpress.com/421/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mattfrear.com&amp;blog=12300335&amp;post=421&amp;subd=mattfrear&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://mattfrear.com/2011/05/05/organise-your-digital-life-part-1-photos/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/5da3065d9a83a23a90c18a5e7d20b180?s=96&#38;d=http%3A%2F%2F1.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">mattfrear</media:title>
		</media:content>

		<media:content url="http://mattfrear.files.wordpress.com/2011/05/my-workspace.jpg" medium="image">
			<media:title type="html">My Workspace</media:title>
		</media:content>

		<media:content url="http://a.img-dpreview.com/reviews/PentaxOptioS/Images/frontview-001.jpg" medium="image">
			<media:title type="html">Pentax Optio S</media:title>
		</media:content>

		<media:content url="http://mattfrear.files.wordpress.com/2011/05/camera.png" medium="image">
			<media:title type="html">camera folder</media:title>
		</media:content>

		<media:content url="http://mattfrear.files.wordpress.com/2011/05/2010.png" medium="image">
			<media:title type="html">2010</media:title>
		</media:content>

		<media:content url="http://mattfrear.files.wordpress.com/2011/05/london.png" medium="image">
			<media:title type="html">london</media:title>
		</media:content>
	</item>
	</channel>
</rss>
