我使用文件上传将文件路径插入到数据库中,并将上传的文件插入到项目目录中的文件中,我添加了我的代码,但效果不佳。
<div class="editor-field create-Bt2">
@Html.EditorFor(model => model.Active)
@Html.ValidationMessageFor(model => model.Active)
</div>
<div>
<p class="create-Bt ">
<input type="submit" value="Create" />
</p>
</div>
[HttpPost]
public ActionResult Create(Category category)
{
if (ModelState.IsValid)
{
var fileName = "";
var fileSavePath = "";
var uploadedFile = Request.Files[0];
fileName = Path.GetFileName(uploadedFile.FileName);
fileSavePath = Server.MapPath("../../Uploads/" +
fileName);
uploadedFile.SaveAs(fileSavePath);
db.Categories.Add(category);
db.SaveChanges();
return RedirectToAction("Index");
}
return View(category);
}