您好,我的复杂对象有问题,这是我的模型
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"})
}
提交后,模型具有名称值,但文件为空。我该怎么做才能获取这种模型的文件。
谢谢。
最佳答案
不要使用平面 @using(Html.BeginForms()) 尝试使用
@using (Html.BeginForm("Submit", "ControllerName", FormMethod.Post, new { enctype = "multipart/form-data"}))
关于c# - 具有 httppostedfilebase 的复杂对象在提交时不会绑定(bind),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45711918/