c# - 具有 httppostedfilebase 的复杂对象在提交时不会绑定(bind)

标签 c# asp.net-mvc-4 asp.net-mvc-5

您好,我的复杂对象有问题,这是我的模型

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/

相关文章:

c# - 如何在 ASP.NET MVC 模型验证中检查字符串是否包含 HTML 代码?

c# - DataGridView.Rows.RemoveAt(int index) 不会删除 Windows 窗体中的行?

asp.net-mvc - 指定名称和 ID 下拉 Razor 技术 asp dot net mvc4

javascript - 将 Javascript ES6 Map() 传递给 MVC Controller

c# - 数据库中已经有一个名为 '__MigrationHistory' 的对象

c# - 包含列表的对象的 ObservableCollection

c# - 如何使用 ADO.NET 创建 Microsoft SQL Server 数据库?

c# - 使用模型值包括报价 ASP MVC4

asp.net-mvc - 选择在 razor html.dropdownlistfor 的页面加载中选择哪个选项

c# - 如何将CSS类添加到MVC中的 Action 链接