C# 在输入不完整的情况下重新提交页面后,上载的文件值将被删除

C# 在输入不完整的情况下重新提交页面后,上载的文件值将被删除,c#,asp.net,asp.net-mvc,C#,Asp.net,Asp.net Mvc,我希望该页面保存上传的文件,即使在没有填写所有表单时单击提交按钮,除非所有表单都已完成 <div class="form-group"> @Html.LabelFor(model => model.cvURL, htmlAttributes: new { @class = "control-label col-md-2" }) <div class="col-lg-10"> @Html.TextBoxF

我希望该页面保存上传的文件,即使在没有填写所有表单时单击提交按钮,除非所有表单都已完成

    <div class="form-group">
        @Html.LabelFor(model => model.cvURL, htmlAttributes: new { @class = "control-label col-md-2" })
        <div class="col-lg-10">
            @Html.TextBoxFor(model => model.cvURL, new { type = "file" })
            @Html.ValidationMessageFor(model => model.cvURL)
        </div>
    </div>




public ActionResult RegisterCandidates(CandidateRegisteration can, HttpPostedFileBase cvURL)
{

    if (ModelState.IsValid)
    {
        if (CheckFileType(cvURL.FileName))
        {
            var fileName = Path.GetFileName(cvURL.FileName);
            var path = Path.Combine(Server.MapPath("~/CVuploads"), fileName);
            can.cvURL = cvURL.FileName;
            cvURL.SaveAs(path);
            db.CandidateRegisteration.Add(can);
            db.SaveChanges();
            return RedirectToAction("Index");
        }
        else
        {
            ViewBag.emailExists = "Not Right extention";
        }

    }

    return View();
} 

@LabelFor(model=>model.cvURL,htmlAttributes:new{@class=“controllabel col-md-2”})
@Html.TextBoxFor(model=>model.cvURL,新的{type=“file”})
@Html.ValidationMessageFor(model=>model.cvURL)
public ActionResult RegisterCandidates(候选注册can,HttpPostedFileBase cvURL)
{
if(ModelState.IsValid)
{
if(检查文件类型(cvURL.FileName))
{
var fileName=Path.GetFileName(cvURL.fileName);
var path=path.Combine(Server.MapPath(“~/CVuploads”),文件名);
can.cvURL=cvURL.FileName;
cvURL.SaveAs(路径);
db.CandidateRegistration.Add(can);
db.SaveChanges();
返回操作(“索引”);
}
其他的
{
ViewBag.emailExists=“不正确扩展”;
}
}
返回视图();
} 

它会从
~/CVuploads
中删除?不会从实际页面中删除。例如,如果表单输入有错误的详细信息或存在用户名,我单击“提交”,则上载的简历会被删除,其他字段或输入的值会保留在表单上。可以尝试设置“值”。。。类似这样:…新的{type=“file”,value=“@Model.cvURL.FileName”}是的,它就是这样工作的