zoukankan      html  css  js  c++  java
  • Mvc学习--1

    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、mvc---表单提交

    今天遇到 如果只是单纯的利用 Html.BeginForm()  就会在前台显示多一个 

    System.Web.Mvc.Html.MvcForm {

    所以要加一个 using()

    @using(Html.BeginForm()) 这样就不会了。



  • 相关阅读:
    Solr的核心操作案例
    分布式锁
    AngularJS——AngularJS实现地址栏取值
    【转】保证消息队列的高可用性
    【转】Spring线程及线程池的使用
    微信支付实现
    分布式id的生成方式——雪花算法
    重载new和delete
    C++工程实践
    语言基础(27):异常处理
  • 原文地址:https://www.cnblogs.com/zxs-onestar/p/5788577.html
Copyright © 2011-2022 走看看