如果我这样写:
表单action =“ Images” method =“ post” enctype =“ multipart / form-data”
有用。
但是在带有“ @”的Razor中,它不起作用。我有没有犯错?
@using (Html.BeginForm("Upload", "Upload", FormMethod.Post,
new { enctype = "multipart/form-data" }))
{
@Html.ValidationSummary(true)
<fieldset>
Select a file <input type="file" name="file" />
<input type="submit" value="Upload" />
</fieldset>
}
我的控制器如下所示:
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Upload()
{
foreach (string file in Request.Files)
{
var uploadedFile = Request.Files[file];
uploadedFile.SaveAs(Server.MapPath("~/content/pics") +
Path.GetFileName(uploadedFile.FileName));
}
return RedirectToAction ("Upload");
}
梵蒂冈之花