HttpPostedFileBase始终提供null,我在网上查看了各种解决方案,但结果没有改变,我正在附加代码,您能帮我吗?
由于我已经有了一个模型,所以我问自己是否可以这样做,所以我不必上传多个文件。
ps:我也尝试更改输入的样式,但未更改 抱歉英语不好,但是我已经翻译了google的翻译
@model WebElementware.Models.TAB_LAVORA_CON_NOI
@{
ViewBag.Title = "WorkWithUs";
}
<form action="@Url.Action("WorkWithUs","Home")" method="post" enctype="multipart/form-data">
@using (Html.BeginForm("WorkWithUs", "Home", FormMethod.Post, new { TBLCN = Model, enctype = "multipart/form-data"}))
{
<label for="file">Inviaci il tuo curriculum:</label>
<input type="file" name="file" id="file" />
}
</form>
<section>
<center>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="Cerca!" class="btn btn-default" />
</div>
</div>
</center>
</section>
控制器
[HttpPost]
public ActionResult WorkWithUs(TAB_LAVORA_CON_NOI TBLCN ,HttpPostedFileBase file)
{
string Message = "";
if (ModelState.IsValid)
{
TBLCN.LETTO = false;
using (DB_WEB_ELEMENTWAREEntities1 DB = new DB_WEB_ELEMENTWAREEntities1())
{
DB.TAB_LAVORA_CON_NOI.Add(TBLCN);
DB.SaveChanges();
}
}
else
{
Message = "Invalid Request";
}
if (file.ContentLength > 0)
{
var fileName = Path.GetFileName(file.FileName);
var path = Path.Combine(Server.MapPath("~/App_Data"), fileName);
file.SaveAs(path);
}
ViewBag.Message = Message;
return View(TBLCN);
}