I am using the jQuery auto complete feature, in which the value are to be stored in a java script array. I have created a function that gives a list with objects that contain user_id and user_name. How to convert it into an array.
public class DocModel { [Required] public String dr_name { get; set; } [Required] public int dr_id { get; set; } public List<DocModel> GetUser() { SqlDataReader sdr = DataAccess.DataAccess.getAllDoctorNames(); List<AECS1.Models.DocModel> DocList = new List<Models.DocModel>(); Models.DocModel Doc; if (sdr.HasRows) { while (sdr.Read()) { Doc = new Models.DocModel(); Doc.dr_id = (int)sdr["dr_id"]; Doc.dr_name = (string)sdr["dr_name"]; DocList.Add(Doc); } } return DocList; } }
This is the view page :
$(function () { var docdata = []; $("#tags").autocomplete({ source: docdata }); });
How to fill up this docdata array ?