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