I am using asp.net mvc 1.0 and I want to return a XML file but I also want to return a strongly typed data back so I can update some fields.
Like the XML file will contain users who failed to be inserted into the database. So I want that to appear as a dialog save box what asp.net mvc return file() would do.
However I also want to return on the page like values like how many users failed to be added, how many users where added, etc.
So I want to use scafolding with the class file I want to pass it along. If this was a view I could pass it along as an object model but I don't see a parameter for that in File().
I also don't want to save the xml file onto the harddrive I want to do it through memory. So have a link that would display on the page to download t开发者_如何学JAVAhe file and show the the data I want would not be desired.
I could be wrong, but I think you'll need to use JavaScript for this. What your're trying to do is a limitation of HTTP and from my understanding of HTTP, you can only return one file type per response since the protocol is a request->response
.
You can have MVC return the strongly typed view in addition to the XML file name inside the ViewData. Then have a JavaScript function change the window.location
property to the file's URL (or make a new window).
I'm not sure about the exact details on how to gracefully have the JavaScript spit the file out like alot of download websites have it.
Edit:
I found how to gracefully
automate the download process, check this question out:
JavaScript automatic download of a file
精彩评论