I develop an asp.net mvc solution with durandal/breeze.
I have a dropdown where list is populated from an Enum provided by Entity Framework Code First. Here is the model server side:
public enum EnumCategory
{
Cat1,
Cat2,
Cat3,
Cat4
}
Here is the table which use this enum:
public class Transport
{
[Key]
public int Id { get; set; }
public EnumCategory Category { get; set; }
...
}
My question: how to retrieve these values of the enum server side to be able to fill my dropdown client side? Do I have to create a new array manually client side like this:
var categories = [
{ id: '' , description: '' },
{ id: 'Cat1', description: 'Category 1' },
{ id: 'Cat2', description: 'Category 2' },
{ id: 'Cat3', description: 'Category 3' },
{ id: 'Cat4', description: 'Category 4' }];
My view display this dropdown like this:
<select data-bind="options: $root.categories,
optionsText: 'description',
optionsValue: 'id',
value: category,
validationOptions: { errorElementClass: 'input-validation-error' },
valueUpdate: 'afterkeydown'">
</select>
It seems redundant to me to have to recreate a list of values client side because we already have this list of values server side.
Any idea?
Thanks.