本文實(shí)例講述了asp.net中MVC借助Iframe實(shí)現(xiàn)無(wú)刷新上傳文件的方法。分享給大家供大家參考。具體實(shí)現(xiàn)方法如下:
var UploadFun = {
CallBack: function (msg) {
$.messager.alert('上傳文件', msg, 'info');
}
};
public void ImportActivityItems()
{
string error = "導(dǎo)入成功";
try
{
var f = Request.Files["activityitemsfile"];
var fpath = Server.MapPath("/Upload/活動(dòng)鏈接數(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)入過(guò)程中發(fā)生錯(cuò)誤,請(qǐng)重試";
}
Response.Write("script type=\"text/javascript\"> parent.UploadFun.CallBack(\"" + error + "\")/script>");
}