Archive for June, 2009

jQuery Validation Plugin – Dynamically change validator message

25 June, 2009 4 comments

Please read Guu’s comment below for a far better solution to this problem!

I’ve been using the jQuery Validation Plugin and needed to change a validation message dynamically based on the user input. I had a quick search but couldn’t find an easy solution. Unfortunately the messages are not changeable after the initial construction of the validator object. I managed to get around the problem by removing the validator an then re-adding with a new message:

Create validator

    rules: {
        EnquiryText: { required: true }
    messages: {
        EnquiryText: "Enquiry must contain an entry."

Dynamically change message

function setEnquiryValidationTo(message) {
    $("#EnquiryText").rules("add", {
        required: true,
        messages: {
            required: message

There may be a better/easier way to do this but I couldn’t find one via Google.

Categories: jQuery Tags:

Building FubuMVC with a portable version of rake

19 June, 2009 1 comment

To build FubuMVC you need to install ruby, rake etc. Unfortunately for me the firewall at work will not allow me to get the rake gem (I’ve downloaded gems before using the HTTP_PROXY setting before but no luck this time). Any hoose I remember reading Stephen Balkum post on packaging up Rake as an executable.  I followed Stephens guide and created a portable rake package which got around my firewall problem but FubuMVC required another gem rubyzip to allow a build.

Adding another gem

Luckily using Stephen’s guide its really easy to add extra gems, you just need to have them installed before you build your exe. So we follow the first part of the process outlined in Stephen’s guide then do the following:

NOTE: In this case we need rubyzip but it could be any old gem.

  • Download rubyzip and extract to contents to c:\rubywork\zip
  • To install rubyzip, at a command prompt in c:\rubywork\zip, run ..\ruby\bin\ruby install.rb
  • Download zlib and extract the zlib1.dll to C:\rubywork\ruby\lib\ruby\1.8\i386-mswin32
  • Rename zlib1.dll to zlib.dll (rubyzip required this extra dll other gems may not)

Now continue part two of the process from Stephen’s guide to compile your very own allinoneruby.exe which includes, rake and rubyzip.

You should now have allinoneruby.exe and rake.rb file.

Building FubuMVC

We can now drop these files into to the FubuMVC project under the build support folder:


We need a helper batch file in the root folder of FubuMVC called rake.bat which contains:

@.\build_support\allinoneruby.exe .\build_support\rake.rb %*

This will be called when we run the build.

Run the build already

Drop to the command prompt and cd into the FubuMVC project root and simply type build. You should get something like:



Don’t want to go through all that? You can download my version of portable rake here (I don’t think I’m breaking any licensing agreements here, this is all open source software. If I am let me know and I’ll remove the link)

DISCLAIMER: I offer no guarantees I can only confirm this works on my machine!

One final note

I’ve used this method to build some of the other open source projects out there which use rake (all the cool kids seem to be using rake) and so far I’ve not had any problems. This could be pretty frictionless way to introduce rake to a team of .net developers who don’t want the overhead of installing ruby on their machines. Just add it to a tools folder check it in to source control they’ll never know!

Categories: FubuMVC, General Tags:

FubuMVC – Resources

18 June, 2009 Comments off

UPDATE: Lots of changes are a foot with FubuMVC so a few new blog posts appearing, I’ll update this post as I find them.

I’m looking at FubuMVC for a side project, I thought it would be useful to collect a list of resources.



Blog posts





Categories: FubuMVC Tags:

Resharper format settings

10 June, 2009 1 comment

I can never remember these so thought it best to write them down. Start with the settings from:

Plus a few extras…

Go to menu Resharper –> Options –> Languages –> C# –> Formatting Style

  • Braces Layout –> All set to (BSD style)
  • Braces Layout –> Empty braces formatting = Together on the same lineimage
  • Blank lines – I don’t like a lot of blank lines so I set mostly to 1/0image
  • Other –> Align Multiline Constructs – Call arguments = Off

  • Other –> Align Multiline Constructs – Expression = Offimage

  • Other –> Other – Indent array, object and collection initializer block = Offimage


Stop Resharper adding regions to interface implementations and nested classes:

Go to menu: Resharper –> Options –> Languages –> C# –> Type Members Layout

Un-tick Use Default Patterns and you get a text area full of xml. Scroll to the bottom and delete the section:

  <ImplementsInterface Immediate="true" Region="${ImplementsInterface} Members"/>


Also  delete the section:

  <Name Region="Nested type: ${Name}"/>


Finally click Ok.

Code Cleanup

Go to menu Resharper –> Options –> Tools –> Code Cleanup

Add a new profile with the following settings:


I didn’t realise I had fiddled with the default settings so much no wonder I can never remember them.

Categories: Resharper Tags:

Setup ASP.NET MVC with Spark View Engine in 5 minutes or less

8 June, 2009 2 comments

Setup folder structure:


Download and put the mvc dll’s in mvc folder and spark dll’s in spark folder.

Create a new application not a mvc application just a standard application. This means you will not get the mvc helpers for creating controllers and views but that’s not a massive loss and has the advantage that you don’t need the mvc installed if you open the solution on another machine.

add new projectChange content of Default.aspx to: <!– Placeholder do not delete! –>

The default.aspx placeholder is required to allow the routing to work.

Delete the code behind files for Default.aspx (Default.aspx.cs, Default.aspx.designer.cs) they are not needed.

Add references to the Spark.dll and Spark.Web.Mvc.dll located in the libs folder.


Add references to mvc System.Web.Routing.dll, System.Web.Abstractions.dll, System.Web.Mvc.dll


Add spark to the web.config:

  <section name="spark" type="Spark.Configuration.SparkSectionHandler, Spark"/>

  <compilation debug="true" />

Debug true shows compilation errors when rendering views.

Add routing to httpModules section of web.config:

<add name="UrlRoutingModule" type="System.Web.Routing.UrlRoutingModule, System.Web.Routing, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>

Add a application.cs which creates the routes and registers the spark view engine:

using System.Collections.Generic;
using System.Web.Mvc;
using System.Web.Routing;
using Spark.Web.Mvc;

namespace Web
    public class Application
        public void RegisterRoutes(IList<RouteBase> routes)
            routes.Add(new Route(
                           new RouteValueDictionary(new {controller = "home", action = "index", id = ""}),
                           new MvcRouteHandler()));

        public void RegisterViewEngine(IList<IViewEngine> engines)

Add a global.asax with the following code behind.


using System;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;

namespace Web
    public class Global : HttpApplication
        protected void Application_Start(object sender, EventArgs e)
            var app = new Application();

        protected void Application_BeginRequest(object sender, EventArgs e)
            string path = Request.AppRelativeCurrentExecutionFilePath;
            if (string.Equals(path, "~/default.aspx", StringComparison.InvariantCultureIgnoreCase) ||
                string.Equals(path, "~/"))

Create content, controllers and view folders in the root of the project:


Create a shared folder in the views folder with a _global.spark file this will be used to share come code with all views.

<use namespace="System.Collections.Generic"/>
<use namespace="System.Web.Mvc.Html"/>

Create a layouts folder in the views folder with a file called application.spark which will be used for the layout of the application very much like a master page.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns="">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <use content="view"/>

The use content view tag highlighted above is replaced by the current view returned by mvc.

Add a HomeController.cs under the controllers folder with the following content:

using System.Web.Mvc;

namespace Web.controllers
    public class HomeController : Controller
        public ActionResult Index()
            return View();

Under the views folder create a home\index.spark with the following content:

<p>Hello spark.</p>

Run the project and you should get:


You can download this sample solution here.

Categories: Mvc, Spark Tags: ,

HOWTO: Add svn:externals in windows using tortoisesvn

4 June, 2009 2 comments

I have a few projects in subversion using the same set of third party tools nant, bdd, mbunit etc. I’ve read its a good idea to put the tools into their own repository and include them in the other projects using an svn:external. The advantage this gives you is any changes you make to the external repository can be updated easily across all projects. Any hoose this is who to do it.

  1. Go to the root of the folder you want to add the externals too.
  2. Right click on the root folder of the project you want to add the external repository to and select TortoiseSVN –> Properties.tortoise_settings[3]   Note: This folder has to be a checked out subversion repository or you’ll not get the context menu! 
  3. You will now see the subversion properties dialog.tortoise_properties[1]
  4. Click the New.. button. You will now see the Add properties dialog.tortoise_add_properties[1]
  5. Select svn:externals from the property name drop down list.
  6. Enter the name you want to give to the external folder followed by the path to your tools repository in property value text area.
    In the example above: tools svn://server/tools/trunk
    Note: You can add more external repositories by simply adding more lines to the property value text area.
  7. Click Ok to add the property will now be listed in the properties dialog.tortoise_properties2[1]
  8. Right click on the root folder and select SVN Update from the menu. Subversion will now pull down the files from the external repository and your done.

Once you check this change in other people checking out from the repository will automatically get the externals folder. Also any changes to the external repository will be updated in this repository on any update. So in this case if I add a new tool or update one of the tools all repositories using this external repository will get the changes on their next update.


  • Don’t forget to give the folder name before the repository address and not just the repository address or you will get an error along the lines of: Error parsing svn:externals property on …tortoise_error[1]
Categories: Subversion Tags: