我有一个带有隐藏字段的简单表单,用于存储日期和可见字段,供用户上传文件:
<form method="post" action="/TestController/SaveCsv">
<div class="toolbar-item">
<div class="toolbar-label">Upload CSV:</div>
<div class="toolbar-value">
<input type="hidden" id="uploadCsvAuthorisedDate" name="uploadCsvAuthorisedDate" data-bind="value: authorisedDate" />
<input type="file" id="uploadCsv" name="uploadCsv" />
</div>
</div>
<div class="toolbar-item">
<button type="submit">Upload CSV</button>
</div>
</form>
这是c#控制器代码:
[HttpPost]
public ActionResult SaveCsv(DateTime uploadCsvAuthorisedDate, HttpPostedFileBase uploadCsv)
{
//additional processing code not important
}
问题: 文件上载字段已正确填充,但uploadCsvAuthorisedDate未填充。
如果我在立即调试窗口中运行以下命令:
Request.Form[0]
Output: Fri May 22 2015 00:00:00 GMT+0200 (South Africa Standard Time)
我得到了我期待的日期。
问题:这是日期格式错误还是参数映射不喜欢隐藏字段的情况?