views:

103

answers:

1

Hi

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 the file and show the the data I want would not be desired.

+1  A: 

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

Baddie
Hmm that sucks because that means I have to save the file on the hard drive and I rather do through mememory.
chobo2
Not necessarily. You can save it in cache/database/session and remove it when it is accessed. Just create a separate action that takes an ID of some sort and returns the proper content from whatever data source you choose.
Baddie
Ah good ideas..
chobo2