William Duffy

Glasgow Based C# ASP.NET Web Developer

Tag archive for ‘ASP.NET’

Using Application_Error in ASP.NET MVC’s global.asax to Handle Errors

ASP.NET MVC’s controllers have great error handling capabilities and can be easily extended to cater for application specific requirements. However, many developer don’t want to manage errors at a controller level and would rather manage 99 percent of errors from a single location. This allows for a single point of error logging, notification and handling. [...]

Clearing ASP.NET Cache

ASP.NET’s caching system is invaluable for speeding up your website and reducing your server/database load. However, sometimes you will find a need to manually clear the cache and allow it to rebuild with fresh data. As simple as this seems it can prove trickier than you would expect. The following code snippet allows you to [...]

Alternating Row Colours in MVC Views

Alternating row colours on tabular data is one of the most common data visualisation styles a web developer has to implement. Almost every project I have built required tabular data, and alternating row colours were key to the clean, easily readable presentation of that data. However, it quickly becomes tiresome writing the logic to work [...]

Ordinal Suffix DateTime Extension Method

In my opinion the most annoying missing piece of date functionality in the .NET framework is an ability to get a DateTime’s ordinal suffix. If you’re as disheartened as me with this then dismay no more. Below is my DateTime extension method that returns the ordinal suffix for the current day of the month. I’ve [...]

Repopulate Html.PasswordFor<> on validation errors

ASP.NET MVC’s HTML helpers are fast and efficient for rendering elements using your model. One of these is the HTML.PasswordFor<> method, which has a little gotcha that many people get caught out with. The HTML.PasswordFor<> method will render a password input to mask keystrokes on the browser but will not populate the value using the [...]

C# Literal Types

When you are specifying literal numeric values in your code you will, on occasion, have to give the compiler a heads-up on the expected type from the declaration. For example, the literal value 5.3 will, by default, be assumed to be a double. As such, the following 1 float result = 5.3 / 12.4; will [...]

RssResult – An ASP.NET MVC RSS ActionResult

One of the most common tasks for data serving websites is offering an RSS feed that users can subscribe to in order to keep up with the latest updates to that data. Previously I posted the article Creating a simple RSS feed using ASP.NET MVC which demonstrated how to create an RSS feed in a [...]

C# boolean to string extension method

One of the most common operations I find myself repeating when programming is writing a boolean value in a human friendly form. Most users, unless geeky and appreciative of the coolness of datatypes, will not be too comfortable with true/false being used in yes/no context. I’m a BIG believer in developing my own reusable code [...]

CSS class property in ASP.NET MVC HtmlAttributes

When adding an ActionLink or using a similar Html helper on your C# ASP.NET MVC views you will on occasions want to pass a css class via the htmlAttributes parameter. As this is normally achieved by creating an anonymous type you may expect the following code snippet to work. 1 <%= Html.ActionLink("My Link", "MyLink", null, [...]

Creating a simple RSS feed using ASP.NET MVC

Looking to serve an rss document via your ASP.NET MVC controller? Here is a simple, quick means to do so. If you are looking for a much neater, smarter, reusable method of serving rss from your controllers check out my ASP.NET MVC RssResult post (coming soon). For the demonstrations below I will be using a [...]