ASP.NET How to return a view and filecontents
I CANT FIGURE THIS OUT MAN WHAT THE HELL
Current code
30 Replies
The html is just a basic form with a button
BUT IT JUST CLOSES THE DAMN PROCESS CUZ IM NOT RETURNING THE VIEW ðŸ˜
first of all why are you using jquery
What should I do that would be better
second of all what exactly are you trying to do
not jquery because its obsolete
So I have a download button and it sends the form data to my controlller and it compiles a application then im trying to send the filecontents back to the user so they can download it but the problem im having is when I download it the program just closes because there is no view to return to im guessing>
But it just closes the program after its downloaded
why are you returning JSON instead of simply returning a file stream
I did that already did not work
That code is chat gpt mostly my code was different but I resorted to gpt after none of my attempts worked at all
thats how i would do it. i dont know how that works with an ajax call but what you could do is POST a form with target=_blank to download the file
Well I was calling the controller like this
Aand the program just dies and exits after Ive downloaded the file
define dies and exits
The program closes
It just exits
After I download the file
i dont think its supposed to do that
uh yeah
ðŸ˜
I tried that it opens a new tab right? then opens the save dialog box
program is open still at this point
Then then then I press save and it just closes
Like
what
put a breakpoint and step through
alright but im sure it just dies once it returns the file since im not returning a view
I have to figure out how to return the file contents and the view
cuz rn its returning the file contents but then it has no view to return to and it just closes that is my theory
i doubt that
Well I cannot step through html code
is it an api route or a page route?
the server code
It works fine I already stepped through
It returns the file just fine thats why I can download the file
It does not work when it is a API route it says "Invalid Type"
this is what happens if i put it asa Api route
to fix that you probably need to specify the accepted types for post body
Ok so, the idea is:
In your view:
@Ketamine Kyle
var
This code is from stack overflow
I just adapted it to the current context
Yeah im doing something similar if mine does not work ill use this thanks so much
Tryna get this done so I can get started on my college revision 🤣
actually you could just use in the view:
Well each user is going to have a different file path based on what they inputted in the text box on the form so im gonna have to make it get the formdata also should be easy tho
Still just closes
So confusing
what in the fuck man
Think I fucked up the code somewhere I had to make alot of changes cuz I have to pass formdata through
Like it starts the download and when I press save it instantly closes the program like instantly like before
It gets too here then when I press save file and it downloads the program exits
How does that even make sense