Showing posts with label models. Show all posts
Showing posts with label models. Show all posts

Tuesday, August 27, 2013

Binding enum arrays with MVC models

The simplicity of model binding in the MVC framework makes it a powerful and pleasant framework to send models up and down to views. But a little short coming prevents the usage of enum arrays and raising maintainability in my opinion. MVC 4 cannot convert / materialize enum values to an array when used in a model. To put it correctly, there is no standard type converter for the job.

This issue manifested when I was working on a checkbox list of statuses that could be selected as a filter. This would then be posted as a comma separated parameter value to be set on the model object. Which is finally used in a LINQ query.