在我MVC3项目,我有以下型号:MVC3提交对我的复杂数据类型返回null
public class CustomerModules
{
public int ModuleId { get; set; }
public string ModuleName { get; set; }
public int CustId { get; set; }
public bool IsActive { get; set; }
public DateTime? ActiveDate { get; set; }
}
public class CustomerModuleList
{
public IEnumerable<CustomerModules> Modules { get; set; }
}
我的控制器如下:
[HttpGet]
public ActionResult EditModules(int custNo)
{
var model = new CustomerModuleList
{
Modules = _customerModules.LoadModulesByCustomerId(custNo)
};
return View(model);
}
[HttpPost]
public ActionResult EditModules(CustomerModuleList model)
{
if (ModelState.IsValid)
{
var custId = model.Modules.First().CustId;
_customerModules.UpdateCustomerModules(model.Modules, custId);
}
return View(model);
}
而我的看法片段是:
<% using (Html.BeginForm("EditModules","Admin",FormMethod.Post, new { enctype = "multipart/form-data" })){ %>
<%: Html.ValidationSummary(true) %>
<fieldset>
<legend>CustomerModuleList</legend>
<table>
<tr>
<th>Module Name</th>
<th>Active</th>
<th>Active Date</th>
</tr>
<% foreach (var module in Model.Modules){%>
<tr>
<td><%:Html.Label(module.ModuleName) %></td>
<td>
<%CustomerModules module1 = module;%>
<%:Html.CheckBoxFor(x=>module1.IsActive) %>
</td>
<td><%:Html.Label(module.ActiveDate.ToString()) %></td>
</tr>
<% } %>
</table>
<p>
<input type="submit" value="Save" />
</p>
</fieldset>
<% } %>
当我提交回控制器IEnumerable<CustomerModules>
模块返回为空。我想知道如何在MVC3中提交复杂类型的IEnumerable
?想法任何人?
非常感谢,我使用MVC 4,并有同样的问题。然而我的名单被称为别的东西,我创建了这个问题,但我发现重命名列表名称帮助... http://stackoverflow.com/questions/22982096/strange-behaviour-with-mvc-posting-list – raklos