asp.net mvc - Redirect / show view after generated file is dowloaded -
i've got controller action downloads dynamically generated file:
public actionresult downloadfile() { var obj = new myclass { mystring = "hello", mybool = true }; var ser = new xmlserializer(typeof(myclass)); var stream = new memorystream(); ser.serialize(stream, obj); stream.position = 0; response.clear(); response.addheader("content-disposition", "attachment; filename=myfile.xml"); response.contenttype = "application/xml"; // write data stream.writeto(response.outputstream); response.end(); return content("downloaded"); }
just reference:
public class myclass { public string mystring { get; set; } public int myint { get; set; } }
this working, , file (myfile.xml) downloaded.
however, message "downloaded" not sent browser.
similarly, if replace return content("downloaded");
return redirect("www.something.com");
browser redirected before file downloads.
as bit of pre-amble, user journey is:
- user fills out form on previous view
- form submitted
- xml generated , downloaded
- user redirected / "downloaded" view shown (so hitting f5 won't re-post form)
each http request can have 1 response - you're trying sneak in 2 (the file, , page).
normally when send "content-disposition: attachment" http header browser stay on current page , pop file save dialog (or automatically save file in downloads).
you're going have change strategy if want prevent re-submission of form. i'd suggest bit of javascript disable form's submit button , show "completed" message in div overlay?
Comments
Post a Comment