泛舟湖上清波郎朗
以下代码可以正常工作:@using (Html.BeginForm("Upload", "Upload", FormMethod.Post, new { enctype = "multipart/form-data" })){ @Html.ValidationSummary(true)
Select a file }并按预期生成: Select a file 在另一方面,如果你正在写其他的服务器端结构的上下文中的代码,如if或foreach您应该删除@之前using。例如:@if (SomeCondition){ using (Html.BeginForm("Upload", "Upload", FormMethod.Post, new { enctype = "multipart/form-data" })) { @Html.ValidationSummary(true) Select a file }}就您的服务器端代码而言,这是继续的方法:[HttpPost]public ActionResult Upload(HttpPostedFileBase file) { if (file != null && file.ContentLength > 0) { var fileName = Path.GetFileName(file.FileName); var path = Path.Combine(Server.MapPath("~/content/pics"), fileName); file.SaveAs(path); } return RedirectToAction("Upload");}