Validation 发生表单刷新时,多部分/表单数据将丢失

Validation 发生表单刷新时,多部分/表单数据将丢失,validation,asp.net-mvc-4,Validation,Asp.net Mvc 4,我有文件输入的表单,但当模型未验证或抛出错误时,我丢失了有关附件的信息,用户需要再次上传文件。其他输入正常,但文件不起作用 查看 @using (Html.BeginForm("Create", "Person", FormMethod.Post, new { enctype = "multipart/form-data" })) { @Html.LabelFor(m => m.AttachmentFile) @Html.TextBoxFor(m => m.Attac

我有文件输入的表单,但当模型未验证或抛出错误时,我丢失了有关附件的信息,用户需要再次上传文件。其他输入正常,但文件不起作用

查看

@using (Html.BeginForm("Create", "Person", FormMethod.Post, new { enctype = "multipart/form-data" }))
{
    @Html.LabelFor(m => m.AttachmentFile)
    @Html.TextBoxFor(m => m.AttachmentFile, new { type = "file" })
    @Html.ValidationMessageFor(m => m.AttachmentFile)

    <input type="submit" value="Submit" />
}

浏览器禁止使用value属性或通过JavaScript在文件输入字段中指定值


这是一种安全措施,用于防止恶意代码设置值(路径)和访问本地文件。

哦,谢谢,我刚刚开始编写javascript:-)
[HttpPost]
public ActionResult Create(CreateVM model)
{
                        try
                        {
                            if (ModelState.IsValid)
                            {
                              // adding to db
                            }
                        }
                        catch (Exception ex)
                        {
                            ModelState.AddModelError(String.Empty, String.Format("Error : {0}", ex.Message));
                        }

  return View(model);
}