Home > Development, Uncategorized > Enum support in ASP.NET MVC

Enum support in ASP.NET MVC

Hi Folks

So what happened to enum support in ASP.NET?

It was working and then, it stopped.

Well enum support is in MVC 5.1 and by default the Visual Studio templates are still using MVC 5.0 for generating new projects.

The solution is simple enough.

  1. Upgrade MVC in the project.
  2. Find all references to enum types and replace EditorFor with EnumDropDownListFor.

E.g. replace

@Html.EditorFor(model => model.Colour)

with

@Html.EnumDropDownListFor(model => model.Colour)

So how do we get our solutions to use 5.1 by default, and going forward 5.2, 6.0, etc?

Good question and one that doesn’t seem to have that easy an answer as if you chase down the project template, held in “C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\ProjectTemplates\CSharp\Web\1033\WebTemplate45”, you’ll find.

    <WizardExtension>
<Assembly>Microsoft.VisualStudio.Web.Project, Version=2.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</Assembly>
<FullClassName>Microsoft.VisualStudio.Web.Project.OneASPNetProjectTemplateWizard</FullClassName>
</WizardExtension>

So its code that does it not configuration.

Thus the best thing seems to be a ‘checklist’ for new projects.

  1. Create Project.
    1. Explicitly select ASP.NET 4.5.1
  2. Update NuGet Packages
    1. MVC ASP.NET 5.1.2

Cheers

Sebastian

  1. No comments yet.
  1. No trackbacks yet.

Leave a comment