Forloop Blog
Nuget Package for Managing Scripts in ASP.NET MVC 4
As per the comments on my previous post about Managing Scripts for Razor Partial Views and Templates in ASP.NET MVC, I've created a Nuget package for the HtmlHelpers used. Go take a look and leave a comment if you find them useful; I plan to add additional helpers to the package over time for general functionality that is useful in any ASP.NET MVC application.
Web API – Binding Complex types from the URI by default for HTTP GET requests
The model binding implementation in ASP.NET Web Api shares some similarities to the model binding you find in ASP.NET MVC and at the same time has some striking differences. For a more detailed discussion on web api parameter binding, check out Mike Stall’s excellent post on the topic. The topic of today’s post is how we define our own convention for parameter binding complex types when the request is a HTTP GET request.
CSV ValueProvider for model binding to collections
TL;DR
I have written a ValueProvider for binding model collections from records in a CSV file. The source code is available on BitBucket.

Model binding in ASP.NET MVC is responsible for binding values to the models that form the parameter arguments to the controller action matched to the route. But where do model binders get these values from? That’s where Value Providers come in; A ValueProvider provides values for model binding and there are ValueProviders for providing values from
Presentations from NDC 2012
The Norwegian Developers Conference is one of the largest .NET Developer conferences of the year, running over several days and including presentations on topics as wide-ranging as software architecture, SOLID principles, Test-Driven Development and more specific introductions to technologies such as ASP.NET 4.5, Web API, NodeJS and NServiceBus. Sufficed to say, there is something there for every .NET developer. Interested in seeing what SignalR is all about? Check out the following presentation from Damian Edwards:
Event Messaging on the client side with jQuery

How many times have you come across the following kind of code in JavaScript
// code in script-1.js // eek, two global variables! var dialog, updateMessage = function updateMessage (message) { dialog.text(message); } // function to run when the DOM has loaded $(function () { // #dialog is just a simple <p> element dialog = $('#dialog'); });then in another script file
// code in script-2.js // function to run when the DOM has loaded $(function () { $('select').change(function () { // update the dialog with the new selection updateMessage('the new value is ' + this.value); }); });All we’re doing here is updating the text of a <p> element in the DOM whenever the value of a <select> element changes. It’s a contrived and trivial example but it perfectly demonstrates the tight coupling between these two script files; if the
updateMessagefunction is renamed, removed or modified to reorder the parameters (let’s put aside the use of arguments for a moment), this is going to break script-2 at runtime. What’s more, usually with these kinds of changes, it’s too easy to forget to search through all script and markup-related files for function usages and modify accordingly. And further still, it's polluted the global namespace with two additional variables (a big no no in JavaScript development),dialogandupdateMessage, to allow script-2 access to the updateMessage function (which needs access to thedialogvariable). There has to be a better way, and there is.Managing Scripts for Razor Partial Views and Templates in ASP.NET MVC
The view engine in ASP.NET MVC is flexible, very flexible. With great flexibility comes great responsibility however, and managing JavaScript files and code blocks can be particularly cumbersome in conjunction with partial views and templates.
C# 5 asynchronous programming
If you missed Anders Hejlsberg talk on the Future directions for C# and Visual Basic, go check it out now, I’ll wait.
Implement Recaptcha properly in ASP.NET MVC
Love them or hate them, the humble CAPTCHA is a tried and trusted approach to mitigating spam content from infiltrating your beautifully crafted application and flooding it with adverts selling all kinds of nefarious goods. Whilst their effectiveness is debatable and the frustration that they bring about in some high, they are relatively simple to use and catch the bulk of user defined content one would want to filter from their site.
Resolving IoC container services for Validation Attributes in ASP.NET MVC
I'm a fan of the Data Annotation Validation attributes to validate user input on both the client and server side for ASP.NET MVC applications. I'm also a fan of Inversion of Control and Dependency Injection to create loosely coupled and flexible applications. There are certain situations where one would wish to inject services into a validation attribute to use during validation; a (somewhat contrived and security cautious) example of this might be providing the user with a <select> element and ask them to choose an option from it and then validate that the option that they have chosen is one that actually exists for the type of items represented in the dropdown. Sure, the RemoteAttribute would allow you to call a server side method via AJAX to perform validation but it does not provide any server side validation, making it more of a convenience solution than a complete and robust one. What would be good is if we could
- provide services to a validation attribute that could be used in the process of validation
- Not have to explicitly resolve services from the container à la the Service Locator (Anti-)Pattern
ASP.NET MVC Permanent 301 redirects for legacy routes
Having a good url routing scheme is extremely important when developing an application. Urls should be canonical to aid in search engine optimization and discoverable in order to aid users in learning where to find application functionality for particular tasks. But there are points in an applications lifecycle where one wishes to change the url routing scheme in order to employ a better one. In such instances, URL redirection can be used to preserve search engine rankings, user bookmarks to specific pages or to allow more than one URL to serve up the same content, as is the case when employing URL shortening.