c# - 选择文件时不发送表单值
问题描述
如果我在不选择文件的情况下提交表单,我可以看到office
参数是通过正确的办公室名称发送的
但是,在从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>
解决方案
感谢君康利的评论,我现在有了这个工作控制器
[HttpPost]
public IActionResult Upload(string office, IFormFile file)
{
return RedirectToAction("Index", new{office = office});
}
推荐阅读
- javascript - 到达.js 没有检测到注入的元素
- angular - 角度 7 - http get 返回空
- .htaccess - .htaccess 不会重定向到 https 版本
- sublimetext3 - 具有非点分隔扩展的 Sublime 文本语法检测
- reactjs - 反应和 reCAPTCHA v3
- ios - 如何在 Swift 4 中通过 html 将图像写入 pdf
- python - 在 python 中对不相关但形状相似的类进行子类型化的模式
- r - 在 r 中随机 x 之后找到一个素数
- reactjs - 来自 Contentful CMS 的资产图像到达我的 Gatsby/React 应用程序,但浏览器错误显示它们为“null”
- architecture - 作为单个单元部署的 N 层应用程序是单体应用程序吗?