HTML BeginCollectionItem返回NULL

时间:2016-04-01 00:17:42

标签: c# asp.net asp.net-mvc asp.net-mvc-4 razor

HTML.BeginCollectionItem不会向控制器返回值。它总是在控制器中返回NULL。如果在另一个局部视图中有部分视图,我不确定是否有任何事情要做。下面是代码/视图的片段。

ProductEditModel

var attributes : NSMutableArray = NSMutableArray(array: super.layoutAttributesForElementsInRect(rect))

ProductAssetAudioEditModel

 public class ProductEditModel
    {
        // Product details displayed on edit form
        public Product ProductModel { get; set; }
        public IList<ProductAssetAudioEditModel> ProductAssetAudios { get; set;}
    }

ProductAssetResourceEditModel

 public class ProductAssetAudioEditModel
 {
        public int ProductId { get; set; }
        public int? ProductAssetId { get; set; }
        public virtual IList<ProductAssetResourceEditModel> ProductAssetResources { get; set; }
}

ProductEditView.cshtml

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; }
    }

_ProductAssetAudioRow.cshtml

<div id="audio">
    @foreach (ProductAssetAudioEditModel audio in Model.ProductAssetAudios)
    {
        Html.RenderPartial("_ProductAssetAudioRow", audio);
    }
</div>

_ProductAssetAudioResource

 @using (Html.BeginCollectionItem("ProductAssetAudios"))
 {
    ....
    <tbody>
        @foreach (var resource in Model.ProductAssetResources)
        {
           Html.RenderPartial("_ProductAssetAudioResource", resource);    

        }
    </tbody>
    .....
  }

在控制器中,即使编辑页面正确绑定属性以进行编辑,ProductAssetResources也为NULL。

我不确定我在这里缺少什么。

-Alan -

0 个答案:

没有答案