I'm trying create a web API for an autocomplete textbox. I have the API working with sample data, but I don't know how to add data from my table.
Here is my controller:
namespace IMDSEbs.Controllers
{
public class CompanyController : ApiController
{
// GET: api/Company/GetCompanyNames
IMDSDataContext dc = new IMDSDataContext();
public List<CompanyName> results = new List<CompanyName>
{
new CompanyName{ID = 1, Name = "Sonu Nigam"},
};
// GET api/values
public IEnumerable<CompanyName> GetCompanyNames(string query)
{
return results.Where(m => m.Name.Contains(query)).ToList();
}
}
}
Here is the table structure (Name is actually the company name):
ID Name
------------------------------------
1 Abc Company
2 cde Company
3 fgh Company
4 ijk Company