Quantcast
Channel: ASP.NET Core
Viewing all articles
Browse latest Browse all 9386

Standard ASP.NET 5 Web API template throws AJAX error whereas MVC template API Controller doesn't

$
0
0

I get a $.get error calling my WebAPI Controller. The data sent by the $.get still gets to the Controller's method and sends back the data but I get no return value. Exactly the same WebAPI controller works in an MVC 6 project.

HTML Page:

function GetById() {
    var key = $("#KeyList").data("kendoDropDownList").value();
    $.get("/api/todo/id", { key: key }, function (data) {
        $("#KeyLabel").html(data.Name);
    })
    .error(alert("error"));
}

Controller:

[HttpGet("{id}",Name="GetTodo")]publicActionResultGetById(string key){var item =TodoItems.Find(key);if(item ==null){returnHttpNotFound();}returnnewObjectResult(item);}

Viewing all articles
Browse latest Browse all 9386

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>