asp.net中MVC借助Iframe實現(xiàn)無刷新上傳文件實例
本文實例講述了asp.net中MVC借助Iframe實現(xiàn)無刷新上傳文件的方法。分享給大家供大家參考。具體實現(xiàn)方法如下:
html:
<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;">選擇文件:</td>
<td>
<input type="file" id="file" name="activityitemsfile" />
</td>
</tr>
</table>
<input type="submit" value="上傳文件" />
<iframe name='hidden_frame' id="hidden_frame" style='display: none'></iframe>
</form>
</div>
CallBack函數(shù):
CallBack: function (msg) {
$.messager.alert('上傳文件', msg, 'info');
}
};
后臺處理:
{
string error = "導入成功";
try
{
var f = Request.Files["activityitemsfile"];
var fpath = Server.MapPath("/Upload/活動鏈接數(shù)據(jù)/");
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 = "導入過程中發(fā)生錯誤,請重試";
}
Response.Write("<script type=\"text/javascript\"> parent.UploadFun.CallBack(\"" + error + "\")</script>");
}
希望本文所述對大家的asp.net程序設計有所幫助。
相關文章
WPF開發(fā)之利用DrawingVisual繪制高性能曲線圖
通過WPF實現(xiàn)大數(shù)據(jù)曲線圖時,如果用最基礎的Canvas來實現(xiàn),性能堪憂。所以本文將利用DrawingVisual繪制高性能曲線圖,感興趣的可以了解一下2022-02-02
ASP.NET中DropDownList和ListBox實現(xiàn)兩級聯(lián)動功能
這篇文章主要介紹了ASP.NET中DropDownList和ListBox實現(xiàn)兩級聯(lián)動功能的相關資料,需要的朋友可以參考下2016-01-01
asp.net Repeater之非常好的數(shù)據(jù)分頁
asp.net Repeater之非常好的數(shù)據(jù)分頁實現(xiàn)代碼。2009-07-07

