In asp.net, MVC uses Iframe to implement a brushless newest upload file instance, mvciframe

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.