mvc2中关于图片上传

controller中的代码:

var file = System.Web.HttpContext.Current.Request.Files[0];
                if (file != null && file.ContentLength > 0)
                {
                    string fileName = Guid.NewGuid().ToString() + Path.GetExtension(file.FileName);
                    string strPath = Path.Combine(System.Web.HttpContext.Current.Server.MapPath(UrlMarks.LogoPath), fileName);
                    app.AppLogo = fileName;
                    file.SaveAs(strPath);
                }

View页面中

<li>
                <%: Html.LabelFor(model => model.AppLogo) %>
                <input type="file" id="fileLogo" name="fileLogo" /><%: Html.HiddenFor(m => m.AppLogo)%>
            </li>

posted @ 2012-05-23 17:17  孙艺玮  阅读(420)  评论(0)    收藏  举报