2
<% using (Html.BeginForm())
{ %>
<fieldset>
<legend>上傳項目材料</legend>
<input type="file" name="File1" />
<input type="submit" value="上傳" />
</fieldset>
<%} %>
動作代碼
[HttpPost]
public ActionResult FileUpLoad(int id, FormCollection form)
{
try
{
var model = db.ProjcetDeclare.First(c => c.id == id);
if (Request.Files.Count==0)
{
return View();
}
string newFile=string.Empty;
var File1 = Request.Files[0];
if (File1.ContentLength == 0)
{
}
newFile = model.Project.pname + DateTime.Now.ToString("yyyyMMddHHmmss") + Path.GetFileName(File1.FileName);
File1.SaveAs(Server.MapPath("/項目材料/" + newFile));
model.XMCL = "/項目材料/" + newFile;
UpdateModel(model);
db.SaveChanges();
return RedirectToAction("Index");
}
catch
{
return View();
}
}
我想 但Request.Files.Count == 0是真的 找不到文件 爲什麼?