【发布时间】:2020-02-26 09:42:34
【问题描述】:
我在 .cshtml 文件中得到以下代码:
<tr>
<td class="registerWidth"><b>Image:</b></td>
<td>
@Html.TextBoxFor(m => m.File, new { type = "file", accept="image/*" })
@Html.ValidationMessageFor(m => m.File, "", new { @class = "redColor" })
</td>
</tr>
这是在我的 ViewModel 中:
public Image File { get; set; }
(图片来自 System.Drawing)
问题是,Controller中的File每次都是null。
public ActionResult Contact(ContactViewModel data)
{
var Image = data.File //data.File is null
}
【问题讨论】:
-
您如何将文件发送到控制器?你能告诉我们吗?
-
@RahulSharma 我正在使用视图模型并且我正在使用 Html.Beginform("Contact", "Home", FormMethod.Post
标签: c# html asp.net asp.net-mvc razor