In asp.net, MVC uses Iframe to implement a brushless newest upload file instance, mvciframe
The example in this article describes how MVC uses Iframe in asp.net to upload files without refreshing the new one. Share it with you for your reference. The specific implementation method is as follows:
Html:
Copy codeThe Code is as follows: <div id = "uploadwindow" style = "display: none;">
<Form action = "/ShopActivitys/ImportActivityItems" id = "form1" name = "form1" enctype = "multipart/form-data" method = "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 = 'den den _ framework' id = "hidden_frame" style = 'display: none'> </iframe>
</Form>
</Div>
CallBack function:
Copy codeCode: var UploadFun = {
CallBack: function (msg ){
$. Messager. alert ('upload file', msg, 'info ');
}
};
Background processing:
Copy codeThe Code is as follows: public void ImportActivityItems ()
{
String error = "imported successfully ";
Try
{
Var f = Request. Files ["activityitemsfile"];
Var fpath = Server. MapPath ("/Upload/activity 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 = "An error occurred during import. Please try again ";
}
Response. Write ("<script type = \" text/javascript \ "> parent. UploadFun. CallBack (\" "+ error +" \ ") </script> ");
}
I hope this article will help you design your asp.net program.