ASP.NET MVC 2 Released

MVC 2 has been released, I’ve been developing an application using the RC and I am very happy with the new features, there are so many, Areas, Auto-Scaffold UI Helpers with Template Customization which I just love.

I’ve just had to un-install my MVC 2 RC and install the official release of MVC 2 and it worked without any problems.

 

  • New Strongly Typed HTML Helpers
  • Enhanced Model Validation support across both server and client
  • Auto-Scaffold UI Helpers with Template Customization
  • Support for splitting up large applications into “Areas”
  • Asynchronous Controllers support that enables long running tasks in parallel
  • Support for rendering sub-sections of a page/site using Html.RenderAction
  • Lots of new helper functions, utilities, and API enhancements
  • Improved Visual Studio tooling support

 

To download click here

For more details check out Scott Gu’s blog on MVC 2 Released

enums with real world names

Enums are a wonderful addition to .Net, but won’t it be nice to have a real world description that you can display to the user interface? Well you can, and here is how define an attribute (or use existing DisplayNameAttribute) and annotate your enum with names as additional meta-data:

public enum Unit
{
    [DisplayName(“Hz”)] Hertz,
    [DisplayName(“%V”)] Volt
}

Conditional Breakpoints

I know that conditional breakpoints have been around for some time, I just keep forgetting how to set it, so I though it should be time write how to set a conditional breakpoint on my blog.

When you only want to break under certain conditions, you can right-click on a breakpoint red circle (or go to the Breakpoints Window and bring up the context menu on a given breakpoint) and select Condition to bring up the dialog box for conditional breakpoints. 

You’re given two options: break only when the specified expression is true or break only when the specified value has changed.  For this example, since I’m in a for loop, i’ll break when the value of result.Id == 22.

You’ll notice that the breakpoint circle now has a red plus on it to indicate it is conditional.

Simple popups or hover overs

Many a time you use the <a href’#’ title=’display a message’ /> to display a message when you want some hover over text to display additional information, which is fine, but what if you want to display some more fancy text, lets say in HTML you are stuck.

So I went on the search to find something that was easy to implement.

I came across a number of different popups

Each having good coverage, but I ended up using overLIB mainly as Nadun at work found it very easy to use.

Here is how I have implement the library

I have implemented a simple jQuery version of the library, I am sure you could extend it to do a lot more, I always say KIS (Keep It Simple)
Add a tag class of overlib and popup tag which holds the popup information, simple, e.g.
<a href=”#” class=”overlib” popup=”Hello World”>Basic popup</a>
If you want to display HTML content in the popup, just added it to the popup tag
<a href=”#” class=”overlib” popup=”<b>Bold</b> can be displayed too”>HTML content</a>
I have also include in my sample the overlib_pagedefaults which sets a few things up for overLIB, but this is not required if you don’t want to use it.
I have attached a fully working sample to make life easier.

overLib.zip (71.66 kb)

How do you retrieving the XmlEnumAttribute values for an Enum

When you are playing with Web Services you quite often find information held in an Attribute, but how do you get it out?

e.g.

public enum Classification {

        [System.Xml.Serialization.XmlEnumAttribute(“Test drive demonstrator”)]
        Testdrivedemonstrator,

        [System.Xml.Serialization.XmlEnumAttribute(“Showroom vehicle”)]
        Showroomvehicle,

 

By using reflection you can gain access to the attribute, here is how:

Type enumType = typeof(velocityUom);

foreach (FieldInfo fi in enumType.GetFields())

{

object[] attrs = fi.GetCustomAttributes(typeof(XmlEnumAttribute), false);

if (attrs.Length > 0)

{

Console.WriteLine(((XmlEnumAttribute)attrs[0]).Name);

}

}

 

Last Years Toys

It’s a new year and it’s must be time for me to go over what toys I have played with in 2009.

  • Balsamiq Mockups must be the best application and tool that I have come across this year, after giving a talk to DotNetDevNet on the application I found that many other developers went ahead and bought the application too.
  • NotePad+, which is an extended version of the very basic default NotePad that comes with Windows.  Just replace your NotePad with this one and off you go.
  • SysInternals Process Explorer I have used every day, mainly due to the fact that Windows does not handle resources and memory that well, so you have to have a tool to sort it out for you when things go wrong.
  • GhostDoc is an internal tool for use with Visual Studio and cuts down the amount of time required for documentation, and does it right all the time.
  • The biggest and most impressive toy last year has to be the purchase of a MacBook, it’s so much easier than Windows 7, XP or Vista, and things just work as they should do, well designed and well throughout, this gets 10 out of 10 for last years toys.
I’m sure I’ve used some other toys last year, but these are the ones that I remember the most.

this and that