I try to upload images to my application, but always returns null. I can not find the problem here. Can you help me? Here is my code.
Model
[Table("Slider")] public partial class Slider : BaseModel { [Required] [StringLength(200)] public string FileName { get; set; } [StringLength(200)] public string Title { get; set; } [StringLength(1000)] public string Description { get; set; } public int? Order { get; set; } } [NotMapped] public class SliderImage : Slider { public HttpPostedFileBase ImageFile { get; set; } }
View
@using (Html.BeginForm(null, null, FormMethod.Post, new { enctype = "multipart/form-data" })) { @Html.AntiForgeryToken() <div class="modal-body"> <div class="form-horizontal"> @Html.ValidationSummary(true, "", new { @class = "text-danger" }) @Html.HiddenFor(model => model.Id) <div class="form-group"> @Html.LabelFor(model => model.FileName, new { @class = "control-label col-md-2" }) <div class="col-md-10"> @Html.TextBoxFor(model => model.FileName, new { @class = "form-control", @readonly = "readonly" }) @Html.ValidationMessageFor(model => model.FileName, "", new { @class = "text-danger" }) </div> </div> <div class="form-group"> @Html.LabelFor(model => model.ImageFile, new { @class = "control-label col-md-2" }) <div class="col-md-10"> @Html.TextBoxFor(m => m.ImageFile, new { @class = "form-control", type = "file" })
controller
public ActionResult Edit(int id) { Slider slider = _db.Sliders.Find(id); if (slider == null) { return HttpNotFound(); } Mapper.CreateMap<Slider, SliderImage>(); SliderImage sliderImage = Mapper.Map<Slider, SliderImage>(slider); return PartialView("_Edit", sliderImage); } [HttpPost] [ValidateAntiForgeryToken] public ActionResult EditSlider([Bind(Include = "Id,FileName,Title,Description,Order,IsActive,Name,ImageFile")] SliderImage sliderImage) { if (ModelState.IsValid) { Mapper.CreateMap<SliderImage, Slider>(); Slider slider = Mapper.Map<SliderImage, Slider>(sliderImage); _db.Entry(slider).State = EntityState.Modified; _db.SaveChanges(); return Json(new { success = true }); } return PartialView("_EditSlider"); }
What am I doing wrong, is it?
Problem Found
I snap a partial view inside the bootstrap popup. When I boot from a popup, the boot returns zero. Instead, if I open a partial view directly in the browser, then the file is present in the model. Thus, there is no problem downloading files. The problem is modal ascent or something like that.
When using the Bootstrap Model 
When using the Directy partial view 
Check the difference found when using the violinist between Modal sending Bootstrap and using partial viewing directly on the next image, respectively

When publishing from a modal popup, the content type changes to application/x-www-form-urlencoded , where, as with the direct use of the partial view, this is multipart/form-data
Found the root of the problem.
$('form', dialog).submit(function () { var $form = $(this); var enctype = $form.attr('id'); $.ajax({ url: this.action, type: this.method, data: $(this).serialize(), success: function (result) { if (result.success) { $('#myModal').modal('hide');
I use AJAX wiring to submit data from my form. Using $(this).serialize() causes ajax success, but the file is not returned because the content type is different. How can i change this?