Controller responds 200 but doesnt send any data in ASP.NET
I have a ASP.NET Core for frontend calling an ASP.NET API. The response of this api is comming as 200 in my frontend controller. When this same endpoint with the same parameters is tested it returns a JSON with an array of "pavimentos".
But in Ajax, data comes as "null" for this call
49 Replies
The Integration method returns the content from the response data
The request is made and status is 200
The API Call with same endpoint retrieves data
Data comes as undefined
Only to show that the response is 200
Your Ajax call seems off
data: {}
indicates to me you are giving it an object
but thats a GET request. GET requests dont have payloads
so you must pass the id via the query string insteadAjax is calling my Controller /Pavimento/ListarPavimentosDoBloco
yeah, which expects an
int
argument
but since its a GET, that argument has to come from the querystring
so your request should be /Pavimento/ListarBlablablbla?idBloco=12312
... no
thats not helping
the problem is that you are trying to pass a payload to a GET request
that. does. not. work.
POST can take a payload (aka request body), but GET cant
for GET, arguments come from route parameters or querystring
I tested it without the call before, it is passed as queryString in this format
Without the api call*
only calling the controller and returning the Id
I don't know the internals of the
Ajax
method
but I'd look in your browser network log for that call
and verify that its passing a querystring for idBloco
and not with the string variant
the int
isnt the problem :p
Im guessing that data: {}
tries to send it as a request body, but you cant do that for GET so it just skips it. That makes the idBloco
default to 0, and thats why you get no resultsthats not the network inspector
If I dont make the API call it display data as the object I creat
that screenshot doesnt show me anything of value tbh
including the "idBloco", being received in the params of ListarPavimentosDoBloco and being rendered
Its is being passed to the function... in the data object
a much simpler way to verify that would be with just setting a breakpoint and using the debugger, no?
or the network inspector
Dude yeah, but I will be honest with you... I dont know where this info is being logged! the debbuger is empty
I'm a Visual Studio Code User, VS is so different!!
but okay, if the value is passed, then you dont really have any issues here - its just a case of checking why your your method isnt working
¯\_(ツ)_/¯
I see Refit. Thats a rest api client generator thingy, right?
yes
yeah, no clue how to debug the internals of that
Program.cs
Idk what I do kakkaka
uh
whats going on here
you have an API, thats just forwarding its requests to another API, that is ALSO running locally?
No. I have a frontend calling this API
This ajax is part of a view
okay, so you have an MVC app using an API?
Yes
I see. Not an architecture I would recommend, but okay.
ok
so all the code and screenshots you've shown so far, thats from the MVC app?
yes
right, well then you need to verify that the API...
1. Gets the right ID in
2. Can fetch the correct data and return it
Its tested
not really
The logs are showing a call for the endpoint with a "1" and status code 200 (IN THE MVC APP)
you've tested it with postman, skipping your entire MVC app
No yeah, but I mean... the API is working
so yeah, it works when its given the correct ID from postman
but you need to verify that the request your MVC app is sending is correct
how can I do so?
my first step would be to place a breakpoint in the API, then have the MVC app make a request
this wont show you the raw request, but it will tell you that the request is sent or not, and it will show you if the ID can be parsed out of the request or not
where do these logs go to?
logs? Who mentioned logs
I said use the debugger
can jump onto voice chat for screensharing if you want
Ok, lets do it
#vc-2