Failure is inevitable


Useful snippets

I had two small “breakthroughs” while coding today that saved me quite a bit of time.  The first dealt with mocking HtmlHelper<T> with Moq for unit testing purposes: /// <summary> /// A mocked-out <see cref="HtmlHelper{TModel}"/> that can be used for testing. /// </summary> /// <typeparam name="TModel">The view model type.</typeparam> public class FakeHtmlHelper<TModel> : HtmlHelper<TModel> where TModel : class { /// <summary> /// Creates the fake. /// </summary> public FakeHtmlHelper... [More]

Exposing the View Model to JavaScript in ASP.NET MVC

The prevailing practice for moving data between the controller and the view in ASP.NET MVC applications is to utilize a view model.  While using a view model from within the view’s ASPX page is quite easy, utilizing it from JavaScript can be more complex.  While JavaScript blocks declared inline on the view page can easily consume values from the model, external script files cannot.  In order to take advantage of script batching and minimization, you should avoid the use of inline script blocks and instead use external JavaScript files (.js).  What happens when you need to ... [More]

My best (or worst) MVC hack to date&hellip;

I really don’t know if I should be proud or embarrassed by what I just implemented.  I’m going to go with “embarrassed”.  If anyone sees a better way to do it, let me know. The Problem I have a multi-tab interface (via jQuery UI  tabs).  The view is strongly-typed and has a view model, so it’s decoupled from the domain objects that are used to populate it.  The view is rendered using the MVC Future expression-based input builders, so instead of Html.TextBox(“Blah”), I’ve got Html.TextBoxFor(m => m.Property).  For those that don’t know, the expression-based bu... [More]

A day in the life of a developer

I just got off the phone from a very frustrating conference call.  Today’s call brought to light something that I want to address.  It’s a misconception that many non-developers have about software developers.  I know this misconception exists because of the way I’ve heard people refer to our profession; because of the way non-developers in our industry often seem to treat developers.  I think there’s a misconception that our days are filled with free time, that we relax and chill, and that our jobs are so easy that they don’t even qualify as real jobs when compared to mo... [More]

Easy vertical and bottom tab panels with jQuery UI

jQuery UI includes a tabs widget that makes it easy to add tab panels to your web applications.  Out-of-the-box, it currently only supports horizontal tab strips across the top of the content, like so: There are samples in the jQuery UI code that show how you can easily achieve either side (vertical) tabs or bottom (horizontal) layouts with some simple jQuery and CSS, but I didn’t want to have to copy-and-paste the code every time I needed non-standard tab layouts.  I’ve packaged the styles and script up into the superTabs library which introduces two new jQuery plug-in methods: ... [More]

Maintaining the expected type in fluent chains

There is a annoying bug in the code I posted for building FusionCharts from ASP.NET MVC.  If you use one of the fluent methods from the abstract builder class, you lose access to the fluent methods on the concrete.  Why is that?  Because the fluent methods on the base class all return the base type: public FusionChartBuilder<T> Caption(string caption) { mCaption = caption; return this; } This means you can’t write code like the following: Html.FusionCharts().Pie2D(Model.Whatever, 400, 400, r => r.Count) //Base-class method .Label(r => r... [More]

A fluent HtmlHelper extension for using FusionCharts in ASP.NET MVC, Part 2

Hey, it only took me nearly a month to write part 2 of this series!  Yeah, I’ve been neglecting this blog a lot lately.  There just aren’t enough hours in the day to write.  In part 1, I discussed charting with ASP.NET MVC and why I decided to use a Flash solution (FusionCharts Free) instead of an ASP.NET control or a JavaScript solution.  Nearly a month later, I’m still very glad I made the switch.  As I said in part 1, FusionCharts Free includes some methods for working with FusionCharts from ASP.NET, and those work fine in both WebForms and MVC applications.... [More]