i am trying to upload file from my PC to local Database with ASP.NET and Getting Object reference not set to an instance of an object. my Controller
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Create(Jobs jobs, HttpPostedFileBase upload)
{
if (ModelState.IsValid)
{
string path = Path.Combine(Server.MapPath("~/Upload"), upload.FileName);
upload.SaveAs(path);
jobs.JobsImg = upload.FileName;
db.Jobs.Add(jobs);
db.SaveChanges();
return RedirectToAction("Index");
}
return View(jobs);
}
Views
@model FindJobs.Models.Jobs
@{
ViewBag.Title = "Create";
Layout = "~/Views/Shared/_MainLayout.cshtml";
}
<h2>Create</h2>
@using (Html.BeginForm("Create" , "Jobs" , FormMethod.Post , new {enctype = "multipart / form-data" }))
{
@Html.AntiForgeryToken()
<div class="form-group">
@Html.LabelFor(model => model.JobsImg, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
<input type="file" name="upload" />
@Html.ValidationMessageFor(model => model.JobsImg, "", new { @class = "text-danger" })
</div>
</div>
the upload file its image. and how can I identify null value
best Regards