如果我在没有选择文件的情况下提交表单,我可以看到office
param是通过正确的办公室名称发送的
但是,从file
输入中选择文件然后提交后,两个参数都会以null
控制器
[HttpPost]
public IActionResult Upload(string office, string path)
{
return RedirectToAction("Index", new{office = office});
}
查看
<div class="row">
<form method="POST" asp-action="Upload" asp-controller="FloorPlan" enctype="multipart/form-data">
<input class="form-control" name="office" type="hidden" value="@ViewContext.RouteData.Values["office"]" />
<input class="form-control" name="path" type="file" />
<input class="form-control" type="submit" value="Upload">
</form>
</div>
答案 0 :(得分:0)
感谢junkangli的评论,我现在有了这个工作控制器
[HttpPost]
public IActionResult Upload(string office, IFormFile file)
{
return RedirectToAction("Index", new{office = office});
}