Perfectly Performing Pretty Pagination!

For various reasons, I’ve struggled creating pagination links for the bottom of my tables.

Perfectly Performing Pretty Pagination
Perfectly Performing Pretty Pagination

Today I sat down and coded a solution I was happy with. I was getting no-where with C# so I sat down and coded the routine in C++.  My head instantly cleared and I belted out an elegant solution that was also readable.

Things to note:

  • Note how the ellipsis (“…”) will break at page 3, but it also skips over page 4 as well. When the current page number is low, this provides a pleasing aesthetic. If this wasn’t the case, it would appear as if page 3 was simply replaced with an ellipsis and thus would serve no real purpose.
    page numbers are intelligently skipped overpage numbers are intelligently skipped over
  • Note the number of elements remains the same, despite pages 3 and 4 removed and replaced by an ellipsis. Another pleasing aesthetic manifests itself when the user clicks between pages where there is an ellipsis transition.

An easy way to merge to RouteValueDictionary objects in ASP.NET MVC4

I wrestled with this problem for a while and finally found a solution I’m happy enough to post here.

Q. Given two classes, is it possible to bundle up their properties into a RouteValueDictionary and pass the results to the RouteAPI or via an ActionLink?


This technique merges to RouteValueDictionary objects using the Union method.

Given the following c# classes…

public class Student
public int StudentID { get; set; }
public string FirstName { get; set; }
public string LastNamse { get; set; }
public string Email { get; set; }
public DateTime DateOfBirth { get; set; }

public class Address
public string StreetLine1 { get; set; }
public string StreetLine2 { get; set; }
public string Suburb { get; set; }
public string State { get; set; }
public string PostCode { get; set; }

…you can easily write out the key/value pairs to a RouteValueDiction object like this:

RouteValueDictionary routeStudent = new RouteValueDictionary(aStudent);
RouteValueDictionary routeAddress = new RouteValueDictionary(homeAddr);

Here’s the tricky part that I’ve not seen anywhere:

RouteValueDictionary routeCombined = new RouteValueDictionary(routeStudent.Union(routeAddress).ToDictionary(k => k.Key, k => k.Value));

Output to the debug window to prove it all works…

foreach (KeyValuePair<string, object> n in routeCombined)
	System.Diagnostics.Debug.WriteLine(n.Key + ": " + n.Value);

…or simply bundle the RouteValues into an ActionLink:

@Html.ActionLink("Click here to pass routeValues to RouteAPI", "MyActionName", routeCombined);

…or otherwise pass to the RouteAPI in your code somewhere.

return this.RedirectToRoute(routeCombined);

If you have this helpful, please tell the world. Also see this same answer on StackOverFlow

The New Firewall

Welcome to the new Firewall that is blocking you from where you want to be.  How would you login if my website offered you all of these choices and you already had several accounts? It’s just a bit crazy I tells you. I like using Google so Google and consolidate everything for me, but what if I really want to interact with both Google and Instagram on a website, which begs the question, why on Earth would  a website offer multiple choices to login in the first place? It probably won’t benefit me at all? Hmm… not sure about that. Tell me your thoughts.

The New Firewall Craziness!
The New Firewall Craziness!

Links for MVC development

Today’s links on MVC development and related technologies, read at your own peril ; )

  • General Discussion–1-you-have-to-migrate-now
  • Javascript
  • CSS

Why you need to sign up to Microsoft’s BizSpark program now!

I recently purchased Windows 8.1 but as it turns out, perhaps I didn’t need too.

I recently signed up for Microsoft’s BizSpark program to develop software solutions for my customers. I was accepted, and within a few day I was gifted with over 900 products from Microsoft’s software library and hundreds of licence keys… essentially for free! Included in the MSDN Library of downloads was Windows 8.1 – Doh!

Oh well… I’ve got my sights on the bigger picture. I was also given $160 worth of credit per month, for three years, to spend on Windows Azure cloud. This is pretty cool. It’s early stages so far, but it appears that this blog will cost me about $20/month to run on Windows Azure… which is about on par with Amazon’s offerings.

I’ve decided to blog my experience with Windows Azure, it’s various cloud offerings and my experience creating software for my customers and market.

If you are a software developer struggling to afford client or server software from Microsoft, then I strongly urge you to seek out the BizSpark program and sign up now!

Test data generator


I’m currently designing an MVC ASP.NET web application with a SQL Server database.

I want my application to process hundreds or thousands of transactions every hour. That being the case, I need to stress test every part including the web server, slq database, indexes, paging, filtering and many other parts of my application.

test data


I developed a c++ console application that will generate as many test records as I want (into the millions). The file below contains about 100,000 test records containing randomized first and last names. (The last names are country specific and the first names are gender specific).

  1. Download Test Data.
  2. Unzip file and import into a temporary table in SQL Server.
    (Note to the Novice: Creating a temporary table might seem like a wasted step, but it’s actually the correct way of doing this).
    USE MyDatabaseName
    CREATE TABLE CSVImport (FirstName nvarchar(20),
    LastName nvarchar(20),
    Gender nvarchar(7),
    Country nvarchar(20))
    BULK INSERT MyDatabaseName.dbo.CSVImport
    FROM "C:TestData.txt"
  3. Inserted the imported data into an existing table in your database.In this example, the ‘People2′ table.
    INSERT INTO People2 (FirstName, LastName)
    SELECT FirstName, LastName FROM CSVImport

Amazon Cloud is my new best friend

After a long hiatus, my website is back online and hosted in the Amazon cloud at Sydney ( I’m gradually migrating all my computer services to the Ubuntu Operating System (LTS) both at home and professionally. My new home office is located in Boorowa and with a bit of luck I’ll get back into programming soon.

Sunset at Boorowa, NSW

Professional Software Lovingly Handcrafted by Zen-Masters of the Software Trade