当前位置: 代码迷 >> ASP.NET >> MVC2中强类型page中下传文Request.Files.Count为0
  详细解决方案

MVC2中强类型page中下传文Request.Files.Count为0

热度:7978   发布时间:2013-02-25 00:00:00.0
MVC2中强类型page中上传文Request.Files.Count为0
大家好!我这个问题是view部分是强类型的,在提交录入数据的同时还要上传文件,可是强类型中指定的类“B_GongGao”中各字段全有值,Request.Files.Count却为0。不管在界面上放置多少个<input type="file" …… />Request.Files.Count总是为0.下面是我的代码,请高人给看一下:
view部分:
HTML code
<%@ Page Title="" Language="C#" MasterPageFile="TzhaobIndex.Master" Inherits="Chaos.PB.Client.WebSite.BaseView<B_GongGao>" %><asp:Content ID="Content3" ContentPlaceHolderID="MainContent" runat="server">    <form id="form1" runat="server" enctype= "multipart/form-data ">     <div class="EditForm">         <p><%=Html.HiddenFor(m=>m.TBLID) %></p>         <p style="text-align:left">             <label for="GONGGAO_NM">公告名称:</label>             <%=Html.TextBoxFor(m=>m.GONGGAO_NM) %></p>         <p style="text-align:left">             <label for="FABU_TM">发布日期:</label>            <%=Html.TextBox("FABU_TM", Model.FABU_TM.ToString("yyyy-MM-dd"))%>            <A onclick="return showCalendar('FABU_TM', 'y-mm-dd',null);"                               href="#"><IMG src="/Content/DatePicker/datepicker.gif" border="0"> </A>            </p>         <p style="text-align:left">             <label for="FABU_MEITI">发布媒体:</label>             <%=Html.TextBoxFor(m=>m.FABU_MEITI) %></p>         <p style="text-align:left">             <label for="ZHBGG_DOC">公告文件:</label>             <%=Html.TextBoxFor(m=>m.ZHBGG_DOC) %><%=Html.HiddenFor(m=>m.ZHBGG_DOCID) %>            <input type="file" id="ZHBGG_DOC_fl" name="ZHBGG_DOC_fl" /></p>         <p style="text-align:left">             <label for="HUIHAN_DOC">确认回函文件:</label>             <%=Html.TextBoxFor(m=>m.HUIHAN_DOC) %><%=Html.HiddenFor(m => m.HUIHAN_DOCID)%>            <input type="file" id="HUIHAN_DOC_fl" name="HUIHAN_DOC_fl" /></p>         <p style="text-align:left">             <label></label>             <input type="submit" value="保存" style="background:#90D6E4; width:50px" /></p>     </div>     </form></asp:Content> 

Action部分:
C# code
[HttpPost]        public ActionResult B_ZhaoBiaoGongGaoEdit(B_ZhaoBiaoGongGao proj)        {            var str = Request.Form["HUIHAN_DOC_fl"];            if (Request.Files.Count > 0)            {                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);                    string a = Server.MapPath("~/UploadFile/Upload/" + fileName);                    c.SaveAs(a);                }                if (string.IsNullOrEmpty(proj.TBLID))                {                    proj.TBLID = Guid.NewGuid().ToString();                    proj.PROJID = DefaultProject.TBLID;                    if (Session["UserID"] != null)//有用户信息写入,如果没有则重新登录                        proj.AddByID = Session["UserID"].ToString();                    else                        return RedirectToAction("LogIn", "LogOn");                    proj.AddDate = DateTime.Now;                    SqlHelper.InsertObjectUseSql<B_GongGao>(proj, p => { });                }                else                {                    SqlHelper.UpdateObjectUseSql<B_GongGao>(proj, p => { });                }            }            return ShowMsg(new List<string>() { "保存成功!" });        }
  相关解决方案