C
C#3mo ago
Raulino

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
No description
49 Replies
Raulino
Raulino3mo ago
The Integration method returns the content from the response data
No description
Raulino
Raulino3mo ago
The request is made and status is 200
No description
Raulino
Raulino3mo ago
The API Call with same endpoint retrieves data
No description
Raulino
Raulino3mo ago
Data comes as undefined
No description
Raulino
Raulino3mo ago
Only to show that the response is 200
No description
Pobiega
Pobiega3mo ago
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 instead
Raulino
Raulino3mo ago
Ajax is calling my Controller /Pavimento/ListarPavimentosDoBloco
No description
Pobiega
Pobiega3mo ago
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
Raulino
Raulino3mo ago
No description
Pobiega
Pobiega3mo ago
... 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
Raulino
Raulino3mo ago
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
Pobiega
Pobiega3mo ago
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 results
Raulino
Raulino3mo ago
No description
No description
Pobiega
Pobiega3mo ago
thats not the network inspector
Raulino
Raulino3mo ago
If I dont make the API call it display data as the object I creat
Pobiega
Pobiega3mo ago
that screenshot doesnt show me anything of value tbh
Raulino
Raulino3mo ago
including the "idBloco", being received in the params of ListarPavimentosDoBloco and being rendered Its is being passed to the function... in the data object
Pobiega
Pobiega3mo ago
a much simpler way to verify that would be with just setting a breakpoint and using the debugger, no? or the network inspector
Raulino
Raulino3mo ago
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!!
Pobiega
Pobiega3mo ago
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
Raulino
Raulino3mo ago
No description
Raulino
Raulino3mo ago
No description
Pobiega
Pobiega3mo ago
¯\_(ツ)_/¯ I see Refit. Thats a rest api client generator thingy, right?
Raulino
Raulino3mo ago
yes
Pobiega
Pobiega3mo ago
yeah, no clue how to debug the internals of that
Raulino
Raulino3mo ago
Program.cs
No description
Raulino
Raulino3mo ago
Idk what I do kakkaka
Pobiega
Pobiega3mo ago
uh whats going on here you have an API, thats just forwarding its requests to another API, that is ALSO running locally?
Raulino
Raulino3mo ago
No. I have a frontend calling this API This ajax is part of a view
Pobiega
Pobiega3mo ago
okay, so you have an MVC app using an API?
Raulino
Raulino3mo ago
Yes
Pobiega
Pobiega3mo ago
I see. Not an architecture I would recommend, but okay.
Raulino
Raulino3mo ago
ok
Pobiega
Pobiega3mo ago
so all the code and screenshots you've shown so far, thats from the MVC app?
Raulino
Raulino3mo ago
yes
Pobiega
Pobiega3mo ago
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
Raulino
Raulino3mo ago
Its tested
Pobiega
Pobiega3mo ago
not really
Raulino
Raulino3mo ago
The logs are showing a call for the endpoint with a "1" and status code 200 (IN THE MVC APP)
No description
Pobiega
Pobiega3mo ago
you've tested it with postman, skipping your entire MVC app
Raulino
Raulino3mo ago
No yeah, but I mean... the API is working
Pobiega
Pobiega3mo ago
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
Raulino
Raulino3mo ago
how can I do so?
Pobiega
Pobiega3mo ago
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
Raulino
Raulino3mo ago
where do these logs go to?
Pobiega
Pobiega3mo ago
logs? Who mentioned logs I said use the debugger can jump onto voice chat for screensharing if you want
Raulino
Raulino3mo ago
No description
Raulino
Raulino3mo ago
Ok, lets do it
Pobiega
Pobiega3mo ago
#vc-2