QUESTION:
I'm having an issue where the Photo1 value is null in the controller post method despite uploading it. Can someone help with this?
This is my model class:
class ProductVM{
public string Name { get; set;}
public string Color {get; set;}
public HttpPostedFileBase Photo1 { get; set; }
}
Below is how I implemented the view using Razor:
@model Project.Models.ProductVM
@using (Html.BeginForm("AddItem","Item", FormMethod.Post, new { enctype = "multipart/form-data" }))
{
@Html.AntiForgeryToken()
@Html.ValidationSummary(true, "", new {@class = "text-danger"})
@Html.EditorFor(model => model.Name, new {htmlAttributes = new {@class"form-control"}})
@Html.ValidationMessageFor(model => model.Name)
// other fields editor's and dropdown's ...
<div class="col-xs-offset-2 col-xs-8 add-item-rectangle"><input type="file" name="@Model.Photo1" id="file"/></div>
<div class="col-xs-10 add-item-rectangle"></div>
<input type="submit" class="btn btn-block add-item-button-text" value="Send"/>
This is the code for the Post Controller method:
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult AddItem(ProductVM product)
{
//**heere when debuging Photo1 is null despite fact that i uploaded photo**
if (!ModelState.IsValid)
{
//... my stuffs
}
//..
return RedirectToAction("Index", "Home");
}