Random thoughts of wisdom - the personal blog of Michael Holm Andersen

jQuery IntelliSense on ASP.NET MVC

If you’re using ASP.NET MVC, you’re probably also using jQuery and hence would like to have IntelliSense support in your ViewPages. According to Scott Gu all you need to do is to make sure you’re having the “-vsdoc.js” file in your script folder (e.g. “jquery-1.3.2-vsdoc.js”) and VS2008 (with the patch installed!) will find this file and jQuery IntelliSense works – however as it turns out if you’re using a path which starts with “/” (as you should!) VS2008 is unable locate the “-vsdoc.js” file and you will not have any jQuery IntelliSense support.

So there’s a little more to know about how exactly jQuery IntelliSense actually works in order to make this work correctly (not to mention IntelliSense support in .ascx files). Luckily Jouni Heikniemi have written a great article about this – check it out:

TamperData – security test your web applications

Working more and more with ASP.NET MVC I’ve found the Tamper Data Firefox Add-on to be quite useful. With this add-on you can view HTTP/HTTPS headers and browser-requests and (which is really awesome) edit POST parameters.

Use this add-on to security test your web applications by modifying POST parameters and simulate a scenario where a user changes/tampers with information sent to your site, like e-commerce sites where a user tries to buy cheap stuff, hack passwords, etc..

LINQ and PagedList

If you’re using LINQ you probably know about the .Skip and .Take methods. However often you need to do paging, hence you probably use something similar to this to get around that:

public PaginatedList(IQueryable<T> source, int pageIndex, int pageSize)
        PageIndex = pageIndex;
        PageSize = pageSize;
        TotalCount = source.Count();
        TotalPages = (int)Math.Ceiling(TotalCount / (double)PageSize);

        this.AddRange(source.Skip(PageIndex * PageSize).Take(PageSize));

However you don’t need the above code – instead take a look at the CodePlex project called PagedList located at

PagedList allows you to take any List<T> and by specifying the page size and desired page index, select only a subset of that list, there’s also a StaticPagedList if you should need that.

Simply download the source, run “Release.bat” to build a release version and reference the .dll file in your solution, then you can have code like this:

var somePage = list.ToPagedList(4, 50); // fifth page, page size = 50

Using Fiddler with the ASP.NET Development server

Fiddler does not by default work together with the ASP.NET development server, however you can easily fix this.

In Fiddler press Ctrl+R (Rules) and go to the “OnBeforeRequest” method, here you add a single line: ="mhanotebook","");

The “mhanotebook” is the name of your computer. The problem is that Fiddler works as a proxy and change this settings in IE7 to forward request to fiddler. however IE7 does not forward calls if the url contains localhost.

After applying the above rule, you can now do a request like this: http://mhanotebook:50016/product and Fiddler will “kick in”, nice :-)

Using LINQPad to query the database

If you’re working with LINQ, you simply can’t live without LINQPad. Below is a screenshot from the query:

from ans in UserAnswers
group ans by new {ans.AnswerId, ans.Answer.Content, 
into myGroup
select new {myGroup.Key.Q, myGroup.Key.Content, Antal = myGroup.Count()}

- being able to do realtime queries against the database is simply awesome. And for only $29 you’ll have Autocompletion (which of course is a must-have / timesaver).

The query shows simple statistics about a poll, where question (Q), answer (Content) and total votes (Antal) is pulled out from the database – I’ve blurred the value of Count() in order to “protect” the clients data…


LINQ Projection and SelectListItem

A small example of where LINQ Projection might come in handy is when you’re working with MVC. In the below example LINQ Projection is used to transform a enumeration of EmployeeCategory instances into an enumeration of SelectListItem instances:

var rep = new mhaRepository();
var person = rep.GetPersonByID(id);
ViewData["EmployeeCategories"] = from c in rep.EmployeeCategories
                         select new SelectListItem
                             Text = c.Name,
                             Value = c.ID.ToString(),
                             Selected = (c.ID == person.CategoryID)

In the View all that is needed to render the DropDownList is this:

<%= Html.DropDownList("EmployeeCategories") %>

Sidebar translation gadget

I’ve been looking for a translation gadget and today I (finally) found a good one:


It uses Google as the “engine “, supports 43 languages and is free:

Canon EOS 350D and Windows 7 x64

Having been out a couple of hours today in the snow with my Canon EOS 350D, I discovered that Windows 7 x64 was unable to detect the camera. After some research I found out that if I changed the camera's USB connection mode from "PC" to "Print/PTP", Windows detected the camera without any problems and I had no problem whatsoever copying my images over.

A few of the images…

IMG_3847IMG_3880IMG_3882 IMG_3931 IMG_3946

Cheap SSD from Kingston

I’ve just ordered a (cheap) 64GB SSD from Kingston for my HP Notebook which was “born” with the factory 5400RPM drive and it’s sloooooooow – however it’s nice to see that prices of SSD’s are finally dropping to a level where it’s affordable to say “bye bye” to those awfully slow HDs that most notebooks ship with.

You can find more info here (in danish)

Gradient typography in webdesign

Just surfin’ the web, I found this nice blog post about gradient typography in webdesign and should I would share it :-)