页面:
  <% using (Html.BeginForm())
       {%>
    <input type="file" id="fileImage" name="fileImage" />&nbsp;&nbsp;
    <input type="submit" value="Upload" />
    <%} %>
代码:
 public ActionResult Index()
        {
            return View();
        }
      [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult Index(FormCollection collection)
        {
            if (Request.Files.Count == 0)
            {
                return View();
            }
            var c = Request.Files[0];
            if (c != null && c.ContentLength > 0)
            {
                int lastSlashIndex = c.FileName.LastIndexOf("\\");
                string fileName = c.FileName.Substring(lastSlashIndex + 1, c.FileName.Length - lastSlashIndex - 1);
                fileName = Path.Combine(CommonUtility.DocImagePath, fileName);
                c.SaveAs(fileName);
            }
          return View();
        } 我就不明白,为什么Request.Files.Count总是等于0请大家帮忙.

解决方案 »

  1.   

    以前我用asp.net mvc 1.0的时候,是可以上传的,
    今天我用的是asp.net mvc 2.0 不知道怎么的就不行了.
      

  2.   

         Ding    观察中...
      

  3.   

    我搞定了,
     <% using (Html.BeginForm("index", "home", FormMethod.Post, new { enctype = "multipart/form-data" }))
           {%>
        <input type="file" id="aaa" name="aaa" />
        <input type="submit" value="保存" />
        <% } %>
    一定要写这个.
    new { enctype = "multipart/form-data" }
    如果没有写,在Action中就得不到文件