页面:
<% using (Html.BeginForm())
{%>
<input type="file" id="fileImage" name="fileImage" />
<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请大家帮忙.
<% using (Html.BeginForm())
{%>
<input type="file" id="fileImage" name="fileImage" />
<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请大家帮忙.
解决方案 »
- Server Error in '/' Application.
- ..这个身份验证权限貌似写死了,该怎么改啊
- 获取域用户SID
- 设定gridview显示列内容格定
- asp.net中怎么做彈出窗口
- 取得传递过来的参数乱码
- 求一个select 语句!因为近来问题多!分小
- 读二进制文件的问题
- 广州的同道兄弟,你们好.我准备过完春节到广州找事做了,请问一般的asp.net程序员价值几何啊?有分相谢!
- js拼接html file控件, 其他file控件选择的内容丢失。 求解决方案
- int?[] productModelIds = {19, 26, 118};, int?是什么意思啊
- 求助:加密前后的密码都知道,有谁知道加密方式
今天我用的是asp.net mvc 2.0 不知道怎么的就不行了.
<% 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中就得不到文件