none
Web API Controller using variable for method name RRS feed

  • Question

  • I'm wondering if this would be accepted behavior, for Web API, or if there is anything wrong with it except being looked down upon.

    Say I make a controller that returns various dropdown types for my site.  Now instead of 2 below, I make around 20 that will fill various dropdowns in my site.  I think it's good to do this instead of making 20 different files right? 

            public IEnumerable<object> Get(string dropdownType)
            {
                if (dropdownType== "Colors")
                    return from a in DBCalls.getColors() select new { Key = a.Key, Value = a.Value };
                if (dropdownType== "Sizes")
                    return from a in DBCalls.getSizes() select new { Key = a.Key, Value = a.Value };
                else
                    return null;

            }

    Then my javascript:

     $("#arPaymentType").kendoComboBox({
                            dataTextField: "Value",

                            dataValueField: "Key",
                            dataSource: {
                                transport: {
                                    read: {

                                        url: "/api/MyDropDowns/",
                                        data: { dropdownType: 'Colors' }
                                    }
                                }
                            }
                        });

    Tuesday, April 1, 2014 9:00 PM

Answers