在Asp.net MVC中进行文件上传可以使用以下步骤来解决问题:
[HttpPost]
public ActionResult UploadFile(HttpPostedFileBase file)
{
if (file != null && file.ContentLength > 0)
{
string fileName = Path.GetFileName(file.FileName);
string filePath = Path.Combine(Server.MapPath("~/Uploads"), fileName);
file.SaveAs(filePath);
}
return RedirectToAction("Index");
}
这样,当用户选择并上传一个文件时,文件将保存在指定的文件夹中。