Reputation: 21
My MVC3 site downloads a .txt file to the user. I want the Download method of my controller to contact the business logic layer, then perform the download, then redirect to a new view that will announce the successful download. The problem is that I can return a view or a file but not both.
[HttpPost]
public ActionResult Download(FormCollection collection)
{
//Contact BLL no problem
return File(Encoding.ASCII.GetBytes("Testing"), "text/plain", "Test.txt");
//OR
return RedirectToAction("OtherActionWithOtherView");
}
I'm happy to go about this differently; any suggestions would be appreciated!
Upvotes: 2
Views: 1047
Reputation: 31651
You need to provide a View page that has an HTML link to the file download action or an Embedded IFrame with src tag assigned to the file download action.
Upvotes: 1
Reputation: 887449
HTTP can't do that.
Instead, return the view only, and put a <meta http-equiv="refresh">
tag in the view that redirects to the download.
Upvotes: 0