Я пытался использовать функцию загрузки в своем приложении ASP.NET, где пользователи могут выбрать файл для загрузки на указанный сервер. Я наткнулся на этот ответ ...
Загрузка файла ASP.NET MVC 3.0
и использовал следующий код из него ...
public ActionResult Index(HttpPostedFileBase file)
{
// Verify that the user selected a file
if (file != null && file.ContentLength > 0)
{
// extract only the filename
var fileName = Path.GetFileName(file.FileName);
// store the file inside ~/App_Data/uploads folder
var path = Path.Combine(Server.MapPath("~/App_Data/uploads"), fileName);
file.SaveAs(path);
}
// redirect back to the index action to show the form once again
return RedirectToAction("Index");
}
@using (Html.BeginForm("Index", "Home", FormMethod.Post, new { enctype = "multipart/form-data" }))
{
<input type="file" name="file" />
<input type="submit" value="OK" />
}
Однако он постоянно говорит мне, что HttpPostedFileBase и «Сервер» не существует в текущем контексте, даже если у меня есть System.Web import