【发布时间】:2013-04-20 05:41:25
【问题描述】:
在我的 MVC3 项目中,我有以下模型:
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);
}
而我的观点 sn-p 是:
<% 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?有什么想法吗?
【问题讨论】:
标签: asp.net-mvc-3