hi im new to C# and i am struggling whith this proplem.
i am trying to upload an image and save it to a local folder, but i am geting a NullReferenceException when i try it..
my controller
[HttpPost]
public ActionResult Index(Picture pic)
{
Picture newPix = pic;
if (newPix.File.ContentLength > 0)
{
var fileName = Path.GetFileName(pic.File.FileName);
//var fileName = pic.File.FileName;
var path = Path.Combine(Server.MapPath("~/Content/images"), fileName);
pic.File.SaveAs(path);
}
return RedirectToAction("Index");
}
my view
<div class="row">
@using (Html.BeginForm(null, null, FormMethod.Post, new { enctype = "multipart/form-data" }))
{
<table>
<tr>
<td>File:</td>
<td><input type="file" id="File" /></td>
<td><input type="submit" name="submit" value="Upload" /></td>
</tr>
</table>
}
my model
{
public HttpPostedFileBase File { get; set; }
}
when i debug, I can see that pic in the controller is NULL,, am i sending the file wrong to the controler from the form?