0

I have a mvc 3 API controller in my project

namespace Carabistouille.Controllers
{
    public class CarabistouilleController : ApiController
    {
        /// <summary>
        /// Method to retrieve all of the carabistouille in the catalog.
        /// Example: GET api/carabistouille
        /// </summary>
        [HttpGet]
        public HttpResponseMessage Get()
        {
            IEnumerable<Carabistouille.DB.Carabistouille> list = Carabistouille.DB.CarabistouilleDAL.GetAllCarabistouille();
            if (list != null)
            {
                return   Request.CreateResponse<IEnumerable<Carabistouille.DB.Carabistouille>>(HttpStatusCode.OK, list);
            }
            else
            {
                return Request.CreateResponse(HttpStatusCode.NotFound);
            }
        }
    }
}

and I want other website to be able to query that API to get the data so I do something like this :

        $("#query_results").empty();
        $("#query_results").append('<table id="ResultsTable" class="BooksTable"><tr><th>Description</th><th>Auteur</th><th>Date</th></tr>');
        $.ajax({
            type: "get",
            contentType: "application/json; charset=utf-8",     

            url: "http://www.Carabistouile.ca/api/carabistouille",
            success: function(msg) {
                    var c = eval(msg.d);
                    for (var i in c) {
                            $("#ResultsTable tr:last").after("<tr><td>" + c.Description + "</td><td>" + c.Auteur + "</td><td>" + c.Date + "</td></tr>");
                        }
                }
        });

Well all I get is :

Failed to load resource: net::ERR_NAME_NOT_RESOLVED

Here is my project architecture

enter image description here

What am I missing ?

ekad
  • 14,436
  • 26
  • 44
  • 46
Francis Groleau
  • 344
  • 4
  • 14

1 Answers1

1

The url you've given in the example returns a 404, which probably means that the routes this controller is supposed to handle have not been registered with the application

Have a look at How to add Web API to an existing ASP.NET MVC 4 Web Application project?

In essence you need to call

WebApiConfig.Register(GlobalConfiguration.Configuration);

In the Application_Start method in the global.asax.cs and make sure your configuration includes the routes this controller is meant to handle

Community
  • 1
  • 1
Louis
  • 593
  • 4
  • 13