0

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;
        }
2
Contributors
1
Reply
12
Views
2 Years
Discussion Span
Last Post by djjeavons
0

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?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.