RE0824C RE0824C - 2 years ago 105
C# Question

Complex object with httppostedfilebase wont bind uppon submit

Hi im having a problem with my complex object, here is my model

public class screen{
      public dictionaryscreen currentvalue {get; set;}
      public dictionaryscreen newvalue {get;set;}
}

public class dictionaryscreen{
      public string name {get; set;}
      public HttpPostedFileBase imagefile {get;set;}
}


And here is my method:

public ActionResult Submit(screen model){
     [Some logic....]
}


And lastly my view

@model project.Models.screen

@using(Html.BeginForms())
{
     @Html.TextBoxFor(m => m.newvalue.name)
     @Html.TextBoxFor(m => m.newvalue.imagefile , new { type = "file"})
}


Upon submission the model has the value of name but the file got null. What can i do to get the file with this kind of model.

Thank you.

Answer Source

Instead of using plane @using(Html.BeginForms()) Try to use

@using (Html.BeginForm("Submit", "ControllerName", FormMethod.Post, new { enctype = "multipart/form-data"}))
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download