Hello, my web api is not working on chrome, but working on IE a open appears at bottom contains .json files . i have all the data on it. can you check my code whats the error?

public class DataController : ApiController
    {
        [Route("dataapi/category")]
        [HttpGet]
        public IEnumerable<vendor_category> Category()
        {
            return vendors();
        }
        public IEnumerable<vendor_category> vendors()
        {
            List<vendor_category> vnd = new List<vendor_category>();
            SqlConnection Con = new SqlConnection(ConfigurationManager.ConnectionStrings["conster"].ConnectionString);
            String Cmdstring = "select * from [Vendors]";
            Con.Open();
            SqlCommand Cmd = new SqlCommand(Cmdstring, Con);
            SqlDataReader dr = Cmd.ExecuteReader();
            while (dr.Read())
            {
                string vid = dr["V_Id"].ToString();
                string cat = dr["Vendors"].ToString();

                vendor_category vn = new vendor_category(vid, cat);
                vnd.Add(vn);
            }
            dr.Close();
            Con.Close();
            return vnd;
        }
        [Route("dataapi/location")]
        [HttpGet]
        public List<vendor_location> Location([FromUri] string q)
        {
            List<vendor_location> vl = new List<vendor_location>();
            SqlConnection Con = new SqlConnection(ConfigurationManager.ConnectionStrings["conster"].ConnectionString);
            String Cmdstring = "select * from [Location] where [Search] LIKE '"+q+"%'";
            Con.Open();
            SqlCommand Cmd = new SqlCommand(Cmdstring, Con);
            SqlDataReader dr = Cmd.ExecuteReader();
            while (dr.Read())
            {
                string id = dr["Id"].ToString();
                string search = dr["Search"].ToString();
                string city = dr["City"].ToString();
                string state = dr["State"].ToString();

                vendor_location vrl = new vendor_location(id,search,city,state);
                vl.Add(vrl);

            }
            dr.Close();
            Con.Close();
            return vl;
        }

Hi

I don't quite follow, are you trying to return a list of objects to a json file to the view (I am assuming this is ASP.NET MVC) as a file or as a model?

What are you trying to do and what is working in IE and not in Chrome?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.