Click here to Skip to main content
16,016,527 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I need to bind data into a dropdown from my database. I have written the following code:

In Model

C#
public static IQueryable<JOBCATEGORY> GetCategory()
       {
           var db = new TKTv2JobEntities();
           var CategoryQry = from c in db.JOBCATEGORies.ToList()
                             select new JOBCATEGORY
                             {
                                 CategoryId = c.CategoryId,
                                 Category = c.Category
                             };
           return CategoryQry.AsQueryable();
       }



In API controller:

XML
public IEnumerable<JOBCATEGORY> getCategory()
        {
            var category = HelpDeskRepository.GetCategory();
            return category.ToList();
        }



In View:

<select style = "font-size: 12px; font-weight: normal;" name="select1" id="select1" data-bind="options: categoryList, optionsText: 'Category', value: CategoryId, optionsCaption: "...Select...""></select>


In js

PHP
self.categoryList=ko.observableArray([]);
    $.getJSON("api/helpdeskapi/getCategory", function (data) {
                $.each(data, function (key, val) {
                    self.categoryList.push();
                  });
            });
Posted
Updated 5-Aug-13 21:46pm
v2

1 solution

value-binding.html[^]

check the documentation for knockout.js..
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900