I have this controller that returns correct results when I call it from a browser.
public async Task<IHttpActionResult> Get(string Id)
{
if (Id == null)
return BadRequest();
try
{
var items = await obj.GetItems(Id);
return Ok(items.ToList());
}
catch (Exception e)
{
return Content(HttpStatusCode.BadRequest, e.Message);
}
}
In my view, I have this jquery.
$.ajax({
type: 'GET',
url: url,
dataType: 'json',
data: {
Id: "5AE158",
},
success: function (data) {
alert('success');
},
error: function (x) {
alert("error");
}
});
When I trigger the function from the UI, I hit a breakpoint in the Controller and I see that it returns correct results, but in the view control flows to the error handler.
I experimented with many combinations of dataType, type and function signatures but I'm not able to get a success return value.
Any help is appreciated.