0

N2CMS uses standard .net enums to define options for editable drop down lists.

My drop down options need to include spaces, but of course you can't have a space in an enum item name.

I had hoped there would be some sort of attribute I could apply to define the text for the options. But I can't see anything anywhere that seems to do it.

andynormancx
  • 13,421
  • 6
  • 36
  • 52

1 Answers1

1

I managed to work out how to do it in the end (by reading the N2 source). You use global resource files.

In particular, the code in EditableEnumAttribute calls HttpContext.GetGlobalResourceObject (by calling Utility.GetGlobalResourceString) for each item in the enum.

So to have enum names with spaces (and other special characters) in them, you add a global resource file that matches the name of the enum, with an entry for each enum item that needs special characters.

The first thing you need to do is add an App_GlobalResources folder to the top level of your project. This is vital, as if you use VS.NET to create resource files elsewhere they don't get created as global ones.

Next create a resource file in App_GlobalResources that matches the name of the enum. It needs to match just the short name of the enum, not the full namespace prefixed name.

Now create an entry in the resource file for each enum item, with the enum item name in the Name column and the name including the special characters in the Value column. You don't need to add an entry for every enum item, only for the ones with special characters (though it would probably make sense to add them all).

andynormancx
  • 13,421
  • 6
  • 36
  • 52