RELATEED CONSULTING
相关咨询
选择下列产品马上在线沟通
服务时间:8:30-17:00
你可能遇到了下面的问题
关闭右侧工具栏

新闻中心

这里有您想知道的互联网营销解决方案
Asp.netmvc4用iframe实现异步上传

1.        Model层用一个TestModel(与上一篇博文的TestModel 相同)

坚守“ 做人真诚 · 做事靠谱 · 口碑至上 · 高效敬业 ”的价值观,专业网站建设服务10余年为成都高空作业车租赁小微创业公司专业提供成都企业网站定制营销网站建设商城网站建设手机网站建设小程序网站建设网站改版,从内容策划、视觉设计、底层架构、网页布局、功能开发迭代于一体的高端网站建设服务。

2.        Controller层:
 public class TestController : Controller
{
//这是iframe页面的action
 public ActionResult IframeView()
        {
           return View();
        }
       public ActionResult View2()
        {
           return View();
        }
       ///
       /// 提交方法
       ///
       /// 模型数据
       /// 上传的文件对象,此处的参数名称要与View中的上传标签名称相同
       ///
        [HttpPost]
       public ActionResult View2(TestModel tm, HttpPostedFileBase file)
        {
           if (file == null)
            {
               return Content("没有文件!", "text/plain");
            }
           var fileName = Path.Combine(Request.MapPath("~/UploadFiles"), Path.GetFileName(file.FileName));
           try
            {
                file.SaveAs(fileName);
                tm.AttachmentPath = fileName;//得到全部model信息
               return Content("上传成功!", "text/plain");
            }
           catch
            {
               return Content("上传异常 !", "text/plain");
            }
        }
}
View层,现在有两个View层,一个是iframe,叫IframeView,一个是View2,分别如下:
IframeView
@model UploadFile.Models.TestModel
@{
    Layout =null;
}
   
   IframeView
   @*enctype= "multipart/form-data"是必需有的,否则action接收不到相应的file,这里报交的action是View2*@
   @using (Html.BeginForm("View2", "Test", FormMethod.Post, new { enctype = "multipart/form-data" }))
    {
       @Html.LabelFor(mod => mod.Title)
       
       @Html.EditorFor(mod => mod.Title)
       
    
       @Html.LabelFor(mod => mod.Content)
       
       @Html.EditorFor(mod => mod.Content) 
       
   
       上传文件
       
       
       
       
       
    }
别一个是View2
@{
    Layout =null;
}
 
   
   iframe异步上传
    
       
   


分享题目:Asp.netmvc4用iframe实现异步上传
URL分享:http://scyingshan.cn/article/jodsec.html