❔ How to pass JS object to function.
How do I pass the JS object to the C# function in that it accepts it as an object of a defined Class?
I looked at an example using Ajax (don't know if that has to do with anything).
https://www.dotnettricks.com/learn/webapi/how-to-pass-javascript-complex-object-to-aspnet-web-api-and-mvc
I'm getting null values.
I tried removing JSON.stringify, but no luck.
Thank you
6 Replies
huh I'm actually not sure it would even bind a route segment to a complex objecy
you should use a post request for this tho
send the object as the body of the request, and set the method to post
well you should be able to figure it out by googling
Like this? Post doesn't even trigger a breakpoint, even if I have it like my original.
Don't append that object to the URL
It's a second parameter of the
fetch()
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.Thanks, and I also forgot to add
[FromBody]
to my function's parameter, GetStockDataAsync([FromBody] Stock stock)
.Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.