public class DoorsModel
{
public DoorsModel() { }
public HttpPostedFileBase Image { get; set; }
public String DoorLayout { get; set; }
public bool ReplicateSettings { get; set; }
public List<DoorDesignModel> Doors { get; set; }
}
public class DoorDesignModel
{
public DoorDesignModel() { }
public HttpPostedFileBase FrontFile { get; set; }
public HttpPostedFileBase BorderFile { get; set; }
}
在我的
View
我有一个普通的表单来填充模型属性,但是
List<DoorDesignModel>
我正在使用一个用户控件
<%Html.RenderPartial("DoorDesign", Model.Doors); %>
DoorDesign.ascx
我有:
<%@ Control
Language="C#" AutoEventWireup="true"
Inherits="System.Web.Mvc.ViewUserControl<List<MyProject.Backend.Models.DoorDesignModel>>" %>
要显示所有表单,我有一个
for
条款
MyProject.Backend.Models.DoorDesignModel field;
for (i = 0; i < Model.Count; i++) {
field = Model[i];
...
}
<input type="file" value="Upload file"
name="Doors.FrontFile[<%: i %>]" id="Doors.FrontFile[<%: i %>]">
但很快我按下提交按钮,我的模型返回一个
null
列表:(
我正在创建和设置一个新列表
public ActionResult Doors()
{
DoorsModel model = new DoorsModel();
model.Doors = new List<DoorDesignModel>();
for (int i= 1; i<= 24; i++) // Add 24 Doors
model.Doors.Add(new DoorDesignModel());
return View(model);
}
[HttpPost]
public ActionResult Doors(DoorsModel model)
{
// model.Doors is always null !!!
if (ModelState.IsValid)
ViewData["General-post"] = "Valid";
else
ViewData["General-post"] = "NOT Valid";
return View(model);
}
我需要什么才能从
RenderPartial
部分?
视图的简单模型