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>
浙公网安备 33010602011771号