码迷,mamicode.com
首页 > Web开发 > 详细

Mvc学习--1

时间:2016-08-19 18:59:28      阅读:137      评论:0      收藏:0      [点我收藏+]

标签:

1、缓存机制
[OutputCache(Duration=10)] 后面的 duration 表示缓存时间 直接放在action上面 是一个特性
2、文件上传
@using (Html.BeginForm("Index", "LoadXml", FormMethod.Post, new { enctype = "multipart/form-data" }))
{
<input type="file" name="file" />
<input type="submit" value="上传"/>
}

后台接受:

 [HttpPost]
        public ActionResult Index(string filenamePath, HttpPostedFileBase file)
        {
            Dictionary<string, string> packdit = new Dictionary<string, string>();
            if (file == null)
            {
                return Content("没有文件!", "text/plain");
            }
            var fileName = Path.Combine(Request.MapPath("~/Upload"), Path.GetFileName(file.FileName));
            try
            {
                if (FileHelper.IsExistFile(fileName))
                {
                    
                }else
                file.SaveAs(fileName);
                //tm.AttachmentPath = fileName;//得到全部model信息
                filenamePath = "../upload/" + Path.GetFileName(file.FileName);
                //return Content("上传成功!", "text/plain");
                //加载excel文档
                 DataTable dt =new DataTable();
                dt = ExcelHelper.ExcelToDataSet("sheel1", fileName);
                
                if (dt != null)
                {
                    foreach (DataRow dr in dt.Rows)
                    {
                        packdit.Add(dr[1].ToString(),dr[2].ToString());
                    }
                }

            } 
            catch
            {
                return Content("上传异常 !", "text/plain");
            }
            return View("show",packdit);
        }

3、excel

 

 



Mvc学习--1

标签:

原文地址:http://www.cnblogs.com/zxs-onestar/p/5788577.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!