I have been messing around with MVC6 controllers and action methods. Something I noticed was that returning JSON results are different in that there is no JsonRequestBehaviour anymore. Ajax Posts are working fine but I have a Get that is consistently returning a 502 (Bad Gateway). The server action method is working correctly.
$.ajax({
type: "GET",
url: "/managingagent/loadagents",
data: "managingagentid=" + @Model.ManagingAgentId,
dataType: "json",
success: function(response) {
alert("SUCCESS");
},
fail: function(response) {
alert("ERROR");
}
});
Action Method
[HttpGet]
public IActionResult LoadAgents(int managingAgentId)
{
var userId = User.GetUserId();
var managingAgent =
_context.ManagingAgentMember.Where(x => x.ApplicationUserId == int.Parse(userId))
.Select(x => x.ManagingAgent).Single();
var agents = _context.ManagingAgentMember.Where(x => x.ManagingAgentId == managingAgent.ManagingAgentId && x.IsActive).ToList();
return Json(agents);
}