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 = "導(dǎo)入成功";
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 = "導(dǎo)入過程中發(fā)生錯誤,請重試";
}
Response.Write("<script type=\"text/javascript\"> parent.UploadFun.CallBack(\"" + error + "\")</script>");
}
希望本文所述對大家的asp.net程序設(shè)計有所幫助。
相關(guān)文章
使用ASP.Net?WebAPI構(gòu)建REST服務(wù)
這篇文章介紹了使用ASP.Net?WebAPI構(gòu)建REST服務(wù)的方法,文中通過示例代碼介紹的非常詳細(xì)。對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下2022-06-06asp.net core集成kindeditor實現(xiàn)圖片上傳功能
這篇文章主要為大家詳細(xì)介紹了asp.net core集成kindeditor實現(xiàn)圖片上傳功能,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下2016-11-11ASP.NET連接數(shù)據(jù)庫并獲取數(shù)據(jù)方法總結(jié)
這篇文章主要介紹了ASP.NET連接數(shù)據(jù)庫并獲取數(shù)據(jù)方法,結(jié)合實例分析總結(jié)了ASP.NET連接數(shù)據(jù)庫及獲取數(shù)據(jù)的相關(guān)實現(xiàn)技巧,并附帶了web.config配置文件的使用方法與相關(guān)注意事項,需要的朋友可以參考下2015-11-11ASP.NET?Core?MVC自定義Tag?Helpers用法介紹
這篇文章介紹了ASP.NET?Core?MVC自定義Tag?Helpers的用法,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2022-02-02CZGL.ProcessMetrics處理監(jiān)控數(shù)據(jù)的三種方式介紹
這篇文章介紹了CZGL.ProcessMetrics處理監(jiān)控數(shù)據(jù)的三種方式,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2022-04-04