Thursday, 28 June 2012

Blocking UI while loading Ajax UpdatePanel

To display a loading image and block the user interface while awaiting new content for an updatepanel you can put this JS code at the bottom of your master page. This uses the jquery.blockui.js plugin and will work site-wide:

Monday, 18 June 2012

Reverse Windows mouse scroll wheel

You're so used to the mouse wheel direction in OSX Lion that you want to reverse your mouse wheel in windows, right? Just change every entry in your registry for 'flipflopwheel' to '1' instead of '0'. Simples.

Wednesday, 13 June 2012

Elmah and MVC - 404 and 403 access and permission errors

I've said it before and I'll say it again - I love Elmah. But today I had trouble getting it to work with my latest MVC project which is due for launch. It took some googling to find out exactly what the problem was, and I had to piece together hints and tips from across the web. So, in short, take the latest Elmah.dll and drop it into your bin directory. Add this line to your RegisterRoutes method in Global.asax.cs:
Then you need to configure your webconfig file like my gist on github. Just look for all the 'Elmah' bits and do the same. Then visit http://yourserver/Elmah.axd and you'll see your error logs. Cool huh?

Monday, 11 June 2012

See 'EntityValidationErrors' property for more details

This morning I was doing a db.SaveChanges() and getting the error:
See 'EntityValidationErrors' property for more details
I'd seen this umpteen times before and always resolved it quickly without having to to look at the EntityValidationErrors property. This morning however I couldn't work our where it was failing, and what field I needed to pay attention to, so I really did need to look into this property. After a bit of googling and good old Stack Overflow, I found this to be the easiest way. Simply put the following into your watch list:

Saturday, 2 June 2012

Using hyphenated data attributes in MVC

In .net MVC this doesn't work:
@Html.TextBox("name", null, new { @class = "input-xlarge", @data-input = "75"})
The hyphenated 'data-input' attribute causes the error "Invalid anonymous type member declarator. Anonymous type members must be declared with a member assignment, simple name or member access." Well, as of MVC 3, you can actually use an underscore instead, like so:
@Html.TextBox("name", null, new { @class = "input-xlarge", @data_input = "75"})
And it'll handle it for you, converting it to a hyphen. It knows you want a hyphen rather than an underscore as underscores aren't valid in html attributes. Lucky huh?