当前位置: 移动技术网 > IT编程>开发语言>.net > ifrem上传文件后显示

ifrem上传文件后显示

2019年03月15日  | 移动技术网IT编程  | 我要评论

易乐圈,成昌勋,泰迪罗宾妻子

ifrem上传文件后显示
1、上传文件按钮   
<a class="btn btn-primary pull-right" id="data-upload" style="margin-right:10px;" data-target="#uploadfiles" data-toggle="modal">上传报告</a>
 
2、上传文件弹出的模态对话框
<!-- 上传报告 -->
<div class="modal fade" id="uploadfiles" tabindex="-1" role="dialog" aria-labelledby="mymodallabel">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" id="closereportid" data-dismiss="modal" aria-label="close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title" id="mymodallabel">上传报告</h4>
            </div>
            <div class="modal-body" style="min-height:450px;">
                <iframe name="upframe" id="upframe" style="width:100%; height:300px; border:0;"></iframe>
            </div>
            <div class="modal-footer">
                <button  id="btn-upload" class="btn btn-primary">上传</button>
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
            </div>
        </div>
    </div>
</div>
 
3、点击弹出按钮触发的事件
 $('#data-upload').click(function(){
        $('#upframe').attr("src","@url.action("upload", "report",new { id=model.project.id})");
    });
 
4、上传文件页面显示的内容
@model project
@{
    layout = null;
}
@using (html.beginform("uploadfile", "report", formmethod.post, new { enctype = "multipart/form-data" }))
{
    <p>
        已传报告:
        @(string.isnullorempty(model.reportfilepath)?"无": model.title.tostring()+".doc")
    </p>
    <input id="reportfile" name="file" type="file" />
                <input type="hidden" value="@model.id" name="id" />
}
 
5、点击上传按钮处理的事件
 $('#btn-upload').click(function(){
        $(window.frames["upframe"].document).find("form").submit();
    });
 
6、上传文件后,控制器中的处理
  /// <summary>
        /// 上传项目报告
        /// </summary>
        /// <param name="id">项目id</param>
        /// <param name="file"></param>
        /// <returns></returns>
        [httppost]
        public actionresult uploadfile(int id, httppostedfilebase file)
        {
            if (file == null)
                return content("没有选择文件");
            if (authcontext.current == null)
                return content("登录异常!");
            using (var db = new entities())
            {
                var model = db.project.find(id);
                if (model == null)
                    return content("项目异常!");
                string path = string.format(@"control\{0}\{1}\{2}.hfrpt", datetime.now.year, datetime.now.month, datetime.now.tostring("dd-hhmmss"));
                var key = filehelper.getfilename(path);
                var temp = filehelper.getfilename(string.format(@"temp\{0}.hfrpt", datetime.now.tostring("yyyymmdd-hhmmss")));
                file.saveas(temp);
                var safekey = id.tostring() + "haifeng%";
                encrypthelper.desencrypt(temp, key, safekey);
                system.io.file.delete(temp);
                model.reportfilepath = path;
                var entry = db.entry(model);
                entry.state = entitystate.modified;
                db.savechanges();
                return content("上传成功");
            }
        }
 

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网