2017-08-16 46 views
2

嗨IM,这里是我的模型与httppostedfilebase复杂的对象不会绑定uppon提交有我的复杂对象的问题

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;} 
} 

这里是我的方法:

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

最后一点我的看法

@model project.Models.screen 

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

提交后,模型具有名称的值,但文件为空。我能做些什么来获得这种模型的文件。

谢谢。

回答

2

而不是使用平面@using的(Html.BeginForms())尝试使用

@using (Html.BeginForm("Submit", "ControllerName", FormMethod.Post, new { enctype = "multipart/form-data"})) 
+1

是的,我注意到。谢谢 – RE0824C