Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does the EnumDataType attribute do in ASP.NET MVC?

I've been using string properties on some of my model objects to represent enums. I'm only using strings because there is not yet enum support in Entity Framework Code First. Anyway, I noticed that there is an attribute in System.ComponentModel.DataAnnotations called EnumDataType. I tried setting this attribute, but it doesn't seem to affect anything.

I should mention that my ultimate goal is to have the appropriate drop-down list appear for any enum type in a "create" or "edit" view. I thought maybe EnumDataType would make this easier in an auto-scaffolding scenario, but I'm not sure this is the case.

Three questions:

  1. Does EnumDataType have a purpose in ASP.NET MVC?
  2. If yes, what does it do?
  3. Do I need my model properties to be int (instead of string) to take advantage of EnumDataType?
like image 447
devuxer Avatar asked Apr 27 '11 00:04

devuxer


1 Answers

EnumDataType is currently supported only by ASP.NET Dynamic Data sites (in .NET 4.0). You can generally build your own custom HTML helper which will take the property check if it contains the attribute (by reflection) and creates drop down for it with values from the linked enum.

like image 197
Ladislav Mrnka Avatar answered Oct 18 '22 10:10

Ladislav Mrnka