The example of this article is about the method that MVC realizes without refreshing upload file in asp.net. Share to everyone for your reference. The implementation methods are as follows:
Html:
Copy Code code as follows:
<div id= "Uploadwindow" style= "Display:none;" >
<form action= "/shopactivitys/importactivityitems" id= "Form1" Name= "Form1" Enctype= "Multipart/form-data" Post "target=" Hidden_frame >
<table style= "width:300px;" >
<tr>
<TD style= "width:80px; Display:block; " > select File:</td>
<td>
<input type= "File" id= "file" name= "Activityitemsfile"/>
</td>
</tr>
</table>
<input type= "Submit" value= "Upload file"/>
<iframe name= ' hidden_frame ' id= ' hidden_frame ' style= ' Display:none ' ></iframe>
</form>
</div>
callback function:
Copy Code code as follows:
var uploadfun = {
Callback:function (msg) {
$.messager.alert (' Uploading Files ', msg, ' info ');
}
};
Background processing:
Copy Code code as follows:
public void Importactivityitems ()
{
String error = "Import succeeded";
Try
{
var f = request.files["Activityitemsfile"];
var Fpath = Server.MapPath ("/upload/Active link Data/");
if (! Directory.Exists (Fpath))
Directory.CreateDirectory (Fpath);
String fullfilename = Fpath + DateTime.Now.ToFileTime () + f.filename;
F.saveas (Fullfilename);
}
catch (Exception ex)
{
Logger.error (ex. ToString ());
Error = "Errors occurred during import, please try again";
}
Response.Write ("<script type=\" text/javascript\) > parent. Uploadfun.callback (\ "" + Error + "\") </script> ");
}
I hope this article will help you with the ASP.net program design.