HTML.BeginCollectionItem不会向控制器返回值。它总是在控制器中返回NULL。如果在另一个局部视图中有部分视图,我不确定是否有任何事情要做。下面是代码/视图的片段。
var attributes : NSMutableArray = NSMutableArray(array: super.layoutAttributesForElementsInRect(rect))
public class ProductEditModel
{
// Product details displayed on edit form
public Product ProductModel { get; set; }
public IList<ProductAssetAudioEditModel> ProductAssetAudios { get; set;}
}
public class ProductAssetAudioEditModel
{
public int ProductId { get; set; }
public int? ProductAssetId { get; set; }
public virtual IList<ProductAssetResourceEditModel> ProductAssetResources { get; set; }
}
public class ProductAssetResourceEditModel
{
public int? ProductAssetResourceId { get; set; }
public int ProductAssetId { get; set; }
public int ResourceNumber { get; set; }
public int? ElectronicFileId { get; set; }
public ElectronicFile ElectronicFile { get; set; }
}
<div id="audio">
@foreach (ProductAssetAudioEditModel audio in Model.ProductAssetAudios)
{
Html.RenderPartial("_ProductAssetAudioRow", audio);
}
</div>
@using (Html.BeginCollectionItem("ProductAssetAudios"))
{
....
<tbody>
@foreach (var resource in Model.ProductAssetResources)
{
Html.RenderPartial("_ProductAssetAudioResource", resource);
}
</tbody>
.....
}
在控制器中,即使编辑页面正确绑定属性以进行编辑,ProductAssetResources也为NULL。
我不确定我在这里缺少什么。
-Alan -