ā post req controller
[HttpPost]
public IActionResult StockData(string stockTicker){
_logger.LogInformation("StockData action invoked with stockTicker: {StockTicker}", stockTicker);
return View("Privacy");
}
no errors but the url doesn't change when return View happens
47 Replies
and the logInformation print are good
Why would the URL change?
still here?
made significant changes now and so
there is no url redirection in the controller when i test
XHR
š
So, uh, I haven't used XHR since the early 2000s, do you... get the data returned from the request anywhere?
Because, yeah, the API controller redirects to another one
But that won't reload the page or anything like thatdoesn't have to be XHR
I mean, XHR or not, just hitting up a controller that redirects somewhere will have no effect on your frontend
Basically I'm trying to do server side redirect or change to another view
Oh wut
Maybe I don't understand how this stuff works
Possibly
So how does return view work then
If everything is rendered server-side, then yes, redirecting to a different controller will actually navigate to that different controller
But when you call a controller from Javascript, it can be redirecting 172 times
And the JS code will follow, yeah
But the page showed in the browser will not
Ah so do the redirection in controller and uh js also?
JS is specifically used to avoid having to reload the page
Oh
As a side note, yeah,
XHR
is a relic of the past
Use fetch
unless you have a gun to your headLol
I tried xhr for synchronus
What's better
Asynchronus js or synchronous js
If something can be done asynchronously it's probably for good reason
So it's not needed?
What's not needed?
Asynchronous code?
It probably is needed
Going out of your way to use decades-old technology just to force something to be synchronous? Unnecessary and outright detrimental
Oh lol
But also what I don't understand is
If client is doing post req to server
And server is returning viee
How come the client view doesn't update
Because it's the JS code that runs the request and receives the response
Not the browser
You can think of it like the Javascript code opening a hidden browser window in the background
Not sure what that really means
You're saying it's the client doing it?
Yes
Javascript makes requests in its own little world
And gets them in their own little world
And if you want any of that to influence what's shown in the broswer, you need to do that explicitly
So it's not possible to do whst I'm doing
Well trying
Because... the controller redirects the javascript to a different view/controller/page/whatever
It does not redirect the browser
Oh bruh wth
š
If you want it to open a new page in the browser with new data and what not, just use a form
You got a YouTube video explaining that
As I said, JS is usef specifically to avoid reloading/redirecting/moving away from the current page
Ohhh I get it's purpose now
So what's the point of making a post to a controller
???
To... send data there?
Yeah
Just for storing?
Like database
uh
Yeah, for example
The reason why I wanted to do whst I wanted btw was to return the view with data
Cause it'd be easy
But ig I can use signal r for that
SignalR will work the same way an API would
Just real-time
Is there a better way to pass information to other views
Without database
I mean, you can continue using the API
But you will have to handle what it returns yourself
Not count on the page updating automagically
What api
Signalr?
No
An API
That you make yourself
With controllers
Like you have it now
Here's an example
Now, mind you, I just wrote it here, on Discord, so it's untested and might contain errors lol
Where do I save the data to
In this case, to a file
Ideally, to a database
Ohhh yeah makes sense
Ty for the understanding lol
Would've never understood that
can u help
With?
Viewbag being null in html
but being aapl in the controller
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.