[英]File upload C# .NET Framework 5
我正在努力使用.NET 5(MVC框架)。 我想上傳文件,但是我不知道如何在控制器中檢索上傳的文件。 它在以前的.NET版本上的工作方式不再起作用(使用HttpPostedFileBase,請參見此處的示例)。
我的表單是帶有文件輸入的非常小的表單:
<form method="post" enctype="multipart/form-data">
<input type="file" name="file">
<input type="submit" name="submit" value="Upload">
</form>
我的控制器如下所示:
public class FittingController : Controller
{
[HttpPost]
public IActionResult Index(IndexViewModel viewModel)
{
// How to retrieve uploaded file here?
}
}
有人已經體驗過.NET版本5嗎?
提前致謝。
我自己找到了解決方案。 我通過請求訪問文件:
IFormFile file = Request.Form.Files.GetFile("file");
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.