I am developing an asp.net mvc solution with durandal / breeze.
I have a drop-down list in which the list is populated from Enum provided by Entity Framework Code First. Here is the server side of the model:
public enum EnumCategory { Cat1, Cat2, Cat3, Cat4 }
Here is the table that uses this enumeration:
public class Transport { [Key] public int Id { get; set; } public EnumCategory Category { get; set; } ... }
My question is: how to get these values for an enumeration server in order to be able to populate my drop down client side? Do I have to manually create a new side, for example:
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 displays this dropdown menu as follows:
<select data-bind="options: $root.categories, optionsText: 'description', optionsValue: 'id', value: category, validationOptions: { errorElementClass: 'input-validation-error' }, valueUpdate: 'afterkeydown'"> </select>
It seems redundant for me to have to reassemble the list of values on the client side, because we already have this list of values on the server side.
Any idea?
Thanks.
Bronzato
source share