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

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异步上传