Home > front end >  ASP.net MVC how to open a new TAB to download files?
ASP.net MVC how to open a new TAB to download files?

Time:10-12

Leadership requires export Excel file can let the user to specify to the exported folder to.
I can think of is to download, let customers save as to save yourself.

The View code below

 
//export button
$(" [name=FileOutputButton] "). Click (function () {

Var form=$(" form# FileOutput ");
//a little...
The form submit ();
});


@ the using (Html. BeginForm (" C05_01_FileOutput ", "C05", FormMethod. Post, new {id="the FileOutput"}))
{
@ Html. HiddenFor (model=& gt; Model. YEARS);
@ Html. HiddenFor (model=& gt; Model. RECORDING_MONTH);
@ Html. HiddenFor (model=& gt; Model. InsertUpdateFlg);
}



The console as follows
 
Public ActionResult C05_01_FileOutput form (XXX)
{

//retrieve data
.

//save address
String tmpPath=Request. MapPath (" ~/template ");
Bine tmpPath=Path.Com (tmpPath + "/C05_01. XLSX");

String tmpDLPath=Request. MapPath (" ~/Tmp ");

//file output
FinancialDB. The fileOutput (form, tmpPath, ref tmpDLPath);

//returns the file
Return the File (new FileStream (tmpDLPath, FileMode. Open), "application/octet - stream", for Server UrlEncode (" C05_01. XLSX "));
}


So do drawback is the current page to download, it performed such as
If the user during the other button won't get the file according to the picture.

So I think, according to the export button when open a new TAB to perform file export processing,
But look for a long time haven't been able to succeed. Seek help from a great god!!!!!!

CodePudding user response:

As if they solved, don't know is there any other better way

View to modify the following
 
$(" [name=FileOutputButton] "). Click (function () {

Var form=$(" form# FileOutput ");

Var years=year [0]. Options [year [0]. Options. SelectedIndex]. Value;
Var month=recordingMonth [0]. Options [recordingMonth [0]. Options. SelectedIndex]. Value;

Window. The open ('/C05/C05_01_FileOutput? Year='+ years + "& amp; The month="+ month);

});
  •  Tags:  
  • ASP
  • Related